niorgai / StatusBarCompat
- четверг, 31 марта 2016 г. в 03:12:00
Java
Status Bar Utils ---- Change Status Bar Mode Simply
Only work for SDK >= 19.
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Add the dependency
dependencies {
compile 'com.github.niorgai:StatusBarCompat:1.0.0'
}
SDK | KITKAT(19) | LOLLIPOP(21) |
---|---|---|
TranslucentStatusBar | SetStatusBarColor |
---|---|
This is a utils for status bar, And you do not need to change your style.xml
file.
//set color for status bar
StatusBarCompat.setStatusBarColor(Activity activity)
StatusBarCompat.setStatusBarColor(Activity activity, int color)
//translucent status bar
StatusBarCompat.translucentStatusBar(activity);
setContentView
StatusBarCompat.translucentStatusBar(activity);
setStatusBarColor
and translucentStatusBar
.StatusBarCompat
, It work perfect.StatusBarCompat1
, It has a black line below statusBar when you call setStatusBarColor
In KitKat.StatusBarCompat2
and call setStatusBarColor
. But it will not work if you call translucentStatusBar
after In KitKat.StatusBarCompat2
and call translucentStatusBar
. But it will not work if you call setStatusBarColor
after In KitKat.StatusBarCompat
is suggested, But you can see their different in my blog Android-transulcent-status-bar.透明状态栏只有在 SDK >= 19 (Android 4.4) 才会生效.
透明状态栏 | 设置状态栏的颜色 |
---|---|
) |
这是一个为了兼容处理状态栏的工具类,可以不需要设置不同的style.xml
文件,提供以下 API :
//设置状态栏的颜色
StatusBarCompat.setStatusBarColor(Activity activity)
StatusBarCompat.setStatusBarColor(Activity activity, int color)
//透明状态栏
StatusBarCompat.translucentStatusBar(activity);
setContentView
方法调用后再设置.StatusBarCompat.translucentStatusBar(activity);
setStatusBarColor
和 translucentStatusBar
中切换.StatusBarCompat
, 效果完美.StatusBarCompat1
,在 Android 4.4-5.0 ,如果调用了 setStatusBarColor
. 状态栏下方会有一条黑线. StatusBarCompat2
并且调用 setStatusBarColor
. 但是在 Android 4.4-5.0 , 如果接下来调用 translucentStatusBar
会无效.StatusBarCompat2
并且调用 translucentStatusBar
. 但是在 Android 4.4-5.0 , 如果接下来调用 setStatusBarColor
会无效.StatusBarCompat
, StatusBarCompat1
, StatusBarCompat2
类,推荐使用StatusBarCompat
类, 其他两个类的实现方式都有一些小问题.在我的博客Android-transulcent-status-bar中可以查看更多细节.
The MIT License (MIT)
Copyright (c) 2016 JQ
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.