Android 沉浸式状态栏 开源 很好用
https://github.com/laobie/StatusBarUtil 推荐
Sample
Download StatusBarUtil-Demo
ChangeLog
CLICK ME
Usage
-
Add the dependencies to your build.gradle file, StatusBarUtil is avaiable in JCenter:
compile 'com.jaeger.statusbarutil:library:1.5.1'
I fixed typo, change "statusbaruitl" to "statusbarutil", please notice this.
-
Call method you need after
setContentView()
, such as :setContentView(R.layout.main_activity);...StatusBarUtil.setColor(MainActivity.this, mColor);
-
If you use this util in a page which containing a
DrawerLayout
, you need addandroid:fitsSystemWindows="true"
forDrawerLayout
in your layout XML:...
-
Set color for swipe back page
Recommend using with bingoogolapple/BGASwipeBackLayout-Android: Android Activity 滑动返回
StatusBarUtil.setColorForSwipeBack(Activity activity, @ColorInt int color, int statusBarAlpha)
-
All
statusBarAlpha
value you set should between 0 ~ 255 -
How to use in Fragment, please read UseInFragmentActivity.java
Handle all Fragments in ViewPager as ImageViewFragment, add a fake View in your Fragment layout as StatusBar :
<?xml version="1.0" encoding="utf-8"?>
The fake StatusBar View height value
statusbar_view_height
defined indimens.xml
~ values-v19/dimens.xml
25dp ~ values/dimens.xml0dp When you change StatusBarColor :
mFakeStatusBar.setBackgroundColor(color);
Then in the Activity which contains ViewPage, just invoke
StatusBarUtil.setTranslucentForImageViewInFragment(UseInFragmentActivity.this, null);
Please read UseInFragmentActivity.java
Features
-
Set status bar color
StatusBarUtil.setColor(Activity activity, int color)
-
Set status bar translucent
StatusBarUtil.setTranslucent(Activity activity, int statusBarAlpha)
-
Set status bar transparent
StatusBarUtil.setTransparent(Activity activity)
-
Set status bar color for
DrawerLayout
StatusBarUtil.setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, int color)
-
Set translucent status bar for using ImageView as head view page
StatusBarUtil.setTranslucentForImageView(Activity activity, int statusBarAlpha, View needOffsetView)
-
Set Light or Dark mode
StatusBarUtil.setLightMode(Activity activity) StatusBarUtil.setDarkMode(Activity activity)
-
Use in fragment
-
Set color for swipe back page
StatusBarUtil.setColorForSwipeBack(Activity activity, @ColorInt int color, int statusBarAlpha)
-
Pass statusBarAlpha param when necessary to change your status bar alpha, which is 112 by default.
License
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer