Android沉浸式状态栏 Sample Download StatusBarUtil-Demo 更新日志 1.2.5 添加 @ColorInt 注解,现在如果传入 R.color.xx,就会提示使用错误 修复 DrawerLayout 内容布局设置 paddding 失效的 bug 1.2.4 修复 setTranslucentForImageViewInFragment() 方法的一个 bug 1.2.3 修复 setTranslucentForImageView ,现在支持传 null 作为 needOffsetView 的值 新增当 fragment 头部是 ImageView 时设置透明状态栏的方法 setTranslucentForImageViewInFragment(Activity activity, ViewneedOffsetView)setTransparentForImageViewInFragment(Activity activity, ViewneedOffsetView) 修复根布局是 CoordinatorLayout 时设置状态栏全透明和半透明的 bug setTranslucentForCoordinatorLayout(Activity activity, int statusBarAlpha) 1.2.0 支持为使用 ImageView 作为头部的界面设置状态栏透明 1.1.1 修复部分 4.4 上的 bug 1.1.0 修复 bug 特性 设置状态栏颜色 StatusBarUtil.setColor(Activity activity, int color) 设置状态栏半透明 StatusBarUtil.setTranslucent(Activity activity, int statusBarAlpha) 设置状态栏全透明 StatusBarUtil.setTransparent(Activity activity) 为包含 DrawerLayout 的界面设置状态栏颜色(也可以设置半透明和全透明) StatusBarUtil.setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, int color) 为使用 ImageView 作为头部的界面设置状态栏透明 StatusBarUtil.setTranslucentForImageView(Activity activity, int statusBarAlpha, View needOffsetView) 在 Fragment 中使用 通过传入 statusBarAlpha 参数,可以改变状态栏的透明度值,默认值是112。 使用 在 build.gradle 文件中添加依赖, StatusBarUtil 已经发布在 JCenter: compile 'com.jaeger.statusbaruitl:library:1.2.5' 在 setContentView() 之后调用你需要的方法,例如: setContentView(R.layout.main_activity);...StatusBarUtil.setColor(MainActivity.this, mColor); 如果你在一个包含 DrawerLayout 的界面中使用, 你需要在布局文件中为 DrawerLayout 添加 android:fitsSystemWindows="true" 属性: <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> ...</android.support.v4.widget.DrawerLayout> 当你设置了 statusBarAlpha 值时,该值需要在 0 ~ 255 之间 在 Fragment 中的使用可以参照 UseInFragmentActivity.java 来实现 Demo下载地址:Android沉浸式状态栏