package com.loocan.shpping;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.support.annotation.ColorInt;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
/**
* Created by Jaeger on 16/2/14.
* <p>
* Email: chjie.jaeger@gmail.com
* GitHub: https://github.com/laobie
*/
public class StatusBarUtil {
public static final int DEFAULT_STATUS_BAR_ALPHA = 112;
private static final int FAKE_STATUS_BAR_VIEW_ID = R.id.statusbarutil_fake_status_bar_view;
private static final int FAKE_TRANSLUCENT_VIEW_ID = R.id.statusbarutil_translucent_view;
private static final int TAG_KEY_HAVE_SET_OFFSET = -123;
/**
* 设置状态栏颜色
*
* @param activity 需要设置的 activity
* @param color 状态栏颜色值
*/
public static void setColor(Activity activity, @ColorInt int color) {
setColor(activity, color, DEFAULT_STATUS_BAR_ALPHA);
}
/**
* 设置状态栏颜色
*
* @param activity 需要设置的activity
* @param color 状态栏颜色值
* @param statusBarAlpha 状态栏透明度
*/
public static void setColor(Activity activity, @ColorInt int color, int statusBarAlpha) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
if (fakeStatusBarView != null) {
if (fakeStatusBarView.getVisibility() == View.GONE) {
fakeStatusBarView.setVisibility(View.VISIBLE);
}
fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
} else {
decorView.addView(createStatusBarView(activity, color, statusBarAlpha));
}
setRootView(activity);
}
}
/**
* 为滑动返回界面设置状态栏颜色
*
* @param activity 需要设置的activity
* @param color 状态栏颜色值
*/
public static void setColorForSwipeBack(Activity activity, int color) {
setColorForSwipeBack(activity, color, DEFAULT_STATUS_BAR_ALPHA);
}
/**
* 为滑动返回界面设置状态栏颜色
*
* @param activity 需要设置的activity
* @param color 状态栏颜色值
* @param statusBarAlpha 状态栏透明度
*/
public static void setColorForSwipeBack(Activity activity, @ColorInt int color, int statusBarAlpha) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
View rootView = contentView.getChildAt(0);
int statusBarHeight = getStatusBarHeight(activity);
if (rootView != null && rootView instanceof CoordinatorLayout) {
final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
coordinatorLayout.setFitsSystemWindows(false);
contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
if (isNeedRequestLayout) {
contentView.setPadding(0, statusBarHeight, 0, 0);
coordinatorLayout.post(new Runnable() {
@Override
public void run() {
coordinatorLayout.requestLayout();
}
});
}
} else {
coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
}
} else {
contentView.setPadding(0, statusBarHeight, 0, 0);
contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
}
setTransparentForWindow(activity);
}
}
/**
* 设置状态栏纯色 不加半透明效果
*
* @param activity 需要设置的 activity
* @param color 状态栏颜色值
*/
public static void setColorNoTranslucent(Activity activity, @ColorInt int color) {
setColor(activity, color, 0);
}
/**
* 设置状态栏颜色(5.0以下无半透明效果,不建议使用)
*
* @param activity 需要设置的 activity
* @param color 状态栏颜色值
*/
@Deprecated
public static void setColorDiff(Activity activity, @ColorInt int color) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
transparentStatusBar(activity);
ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
// 移除半透明矩形,以免叠加
View fakeStatusBarView = contentView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
if (fakeStatusBarView != null) {
if (fakeStatusBarView.getVisibility() == View.GONE) {
fakeStatusBarView.setVisibility(View.VISIBLE);
}
fakeStatusBarView.setBackgroundColor(color);
} else {
contentView.addView(createStatusBarView(activity, color));
}
setRootView(activity);
}
/**
* 使状态栏半透明
* <p>
* 适用于图片作为背景的界面,此时需要图片填充到状态栏
*
* @param activity 需要设置的activity
*/
public static void setTranslucent(Activity activity) {
setTranslucent(activity, DEFAULT_STATUS_BAR_ALPHA);
}
/**
* 使状态栏半透明
* <p>
* 适用于图片作为背景的界面,此时需要图片填充到状态栏
*
* @param activity 需要设置的activity
* @param statusBarAlpha 状态栏透明度
*/
public static void setTranslucent(Activity activity, int statusBarAlpha) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
setTransparent(activity);
addTranslucentView(activity, statusBarAlpha);
}
/**
* 针对根布局是 CoordinatorLayout, 使状态栏半透明
* <p>
* 适用于图片作为背景的界面,此时需要图片填充到状态栏
*
* @param activity 需要设置的activity
* @param statusBarAlpha 状态栏透明度
*/
public static void setTranslucentForCoordinatorLayout(Activity activity, int statusBarAlpha) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
transparentStatusBar(activity);
addTranslucentView(activity, statusBarAlpha);
}
/**
* 设置状态栏全透明
*
* @param activity 需要设置的activity
*/
public static void setTranspare
没有合适的资源?快使用搜索试试~ 我知道了~
Android商城购物车页面实现
共103个文件
xml:55个
bin:10个
png:8个
5星 · 超过95%的资源 需积分: 38 82 下载量 174 浏览量
2018-09-28
16:32:22
上传
评论 6
收藏 848KB RAR 举报
温馨提示
此项目实现了商城购物车部分功能,包含侧滑删除,侧滑删除类库所用EasySwipeMenuLayout,项目博客地址链接:https://blog.csdn.net/loocanp/article/details/82883640
资源推荐
资源详情
资源评论
收起资源包目录
Android商城购物车页面实现 (103个子文件)
gradlew.bat 2KB
fileSnapshots.bin 3.46MB
classAnalysis.bin 1.24MB
jarAnalysis.bin 586KB
taskHistory.bin 402KB
fileHashes.bin 401KB
taskHistory.bin 78KB
taskJars.bin 26KB
resourceHashesCache.bin 21KB
last-build.bin 1B
built.bin 0B
.gitignore 127B
.gitignore 8B
build.gradle 1KB
build.gradle 573B
settings.gradle 16B
gradlew 5KB
gradle-wrapper.jar 52KB
StatusBarUtil.java 27KB
ViewHolder.java 8KB
MainActivity.java 7KB
CartAdapter.java 3KB
CommonAdapter.java 2KB
ExampleInstrumentedTest.java 763B
ExampleUnitTest.java 412B
ic_launcher.jpg 17KB
ic_launcher.jpg 17KB
ic_launcher.jpg 17KB
ic_launcher.jpg 17KB
ic_launcher.jpg 17KB
taskHistory.lock 17B
javaCompile.lock 17B
fileContent.lock 17B
fileHashes.lock 17B
cache.properties.lock 2B
ic_launcher_round.png 15KB
ic_launcher_round.png 10KB
ic_launcher_round.png 7KB
ic_launcher_round.png 5KB
ic_launcher_round.png 3KB
img_check_no.png 2KB
img_check_yes.png 2KB
fanhui.png 1KB
proguard-rules.pro 772B
gradle.properties 747B
local.properties 449B
gradle-wrapper.properties 242B
cache.properties 57B
workspace.xml 177KB
ic_launcher_background.xml 6KB
item_shopcart_product.xml 5KB
dimens.xml 4KB
app_title.xml 3KB
activity_main.xml 3KB
item_cehua.xml 2KB
ic_launcher_foreground.xml 2KB
misc.xml 2KB
com_android_support_test_espresso_espresso_idling_resource_3_0_2.xml 765B
com_android_support_animated_vector_drawable_27_1_1.xml 742B
com_android_support_support_vector_drawable_27_1_1.xml 737B
AndroidManifest.xml 726B
com_scwang_wave_MultiWaveHeader_1_0_0_alpha_1.xml 724B
com_android_support_support_core_utils_27_1_1.xml 712B
com_android_support_test_espresso_espresso_core_3_0_2.xml 710B
com_android_support_support_fragment_27_1_1.xml 702B
com_android_support_recyclerview_v7_27_1_1.xml 697B
com_android_support_support_core_ui_27_1_1.xml 697B
com_android_support_support_compat_27_1_1.xml 692B
android_arch_lifecycle_livedata_core_1_1_0.xml 688B
com_android_support_appcompat_v7_27_1_1.xml 682B
android_arch_lifecycle_viewmodel_1_1_0.xml 668B
com_jakewharton_butterknife_8_8_1.xml 664B
com_android_support_test_monitor_1_0_2.xml 662B
android_arch_lifecycle_runtime_1_1_0.xml 658B
com_android_support_test_runner_1_0_2.xml 657B
android_arch_core_runtime_1_1_0.xml 647B
gradle.xml 626B
com_jakewharton_butterknife_annotations_8_8_1_jar.xml 612B
com_android_support_support_annotations_27_1_1_jar.xml 609B
org_hamcrest_hamcrest_integration_1_3_jar.xml 578B
runConfigurations.xml 564B
text_angle_right.xml 559B
text_angle_gray.xml 558B
org_hamcrest_hamcrest_library_1_3_jar.xml 557B
android_arch_lifecycle_common_1_1_0_jar.xml 547B
org_hamcrest_hamcrest_core_1_3_jar.xml 543B
com_squareup_javawriter_2_1_1_jar.xml 538B
android_arch_core_common_1_1_0_jar.xml 533B
javax_inject_javax_inject_1_jar.xml 528B
com_android_support_constraint_constraint_layout_1_1_3.xml 501B
com_github_anzaizai_EasySwipeMenuLayout_1_1_2.xml 496B
junit_junit_4_12_jar.xml 487B
ids.xml 484B
colors.xml 446B
styles.xml 442B
com_android_support_constraint_constraint_layout_solver_1_1_3_jar.xml 425B
modules.xml 375B
com_google_code_findbugs_jsr305_2_0_1_jar.xml 359B
net_sf_kxml_kxml2_2_3_0_jar.xml 285B
text_angle.xml 278B
共 103 条
- 1
- 2
资源评论
- qq_401246392018-10-16谢谢博主,不错
- cuckoochun2019-04-16感谢分享感谢
打酱油的日光灯
- 粉丝: 78
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功