Status Bar Utils ---- Change Status Bar Mode Simply
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 {
// After AndroidX
implementation ('com.github.niorgai:StatusBarCompat:2.3.3', {
exclude group: 'androidx.appcompat:appcompat'
exclude group: 'com.google.android.material:material'
})
// Before AndroidX
compile ('com.github.niorgai:StatusBarCompat:2.1.4', {
exclude group: 'com.android.support'
})
}| KITKAT(19) | LOLLIPOP(21) |
|---|---|
| TranslucentStatusBar | SetStatusBarColor |
|---|---|
This is a utils for status bar, And you do not need to change your style.xml file.
The most important feature is you can toggle setStatusBarColor and translucentStatusBar without recreate activity.
…setContentView StatusBarCompat.translucentStatusBar(activity);changeToLightStatusBar() at last.Demo shows One Activity with four Fragments.
setStatusBarColor method, SeekBar can change statusBar's alpha.translucentStatusBar method, when sdk >= 21, button can toggle hide/show statusBar's shadow.setStatusBarColor method, show how to compat for DrawerLayout and CoordinatorLayout.setStatusBarColorForCollapsingToolbar method, compat for CollapsingToolbarLayout.These problem only show in SDK between 19 and 21:
TabActivity, It will show a black line in contentView, so you can call StatusBarCompat.setStatusBarColor(Activity activity, int statusColor, int alpha) and the suggest alpha is 112.DrawerLayout, let its child view set fitsSystemWindow to false.translucentStatusBar, the method set View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN to Window, so there will be AndroidBug5497 if work with softInputKeyboard, try Workaround to get help.透明状态栏只有在 SDK >= 19 (Android 4.4) 才会生效.
| 透明状态栏 | 设置状态栏的颜色 |
|---|---|
这是一个为了兼容处理状态栏的工具类,可以不需要设置不同的style.xml文件,最重要的特性就是可以在**不重启 Activity 的情况下切换 setStatusBarColor 和 translucentStatusBar **. 提供以下 API :
…setContentView 方法调用后再设置.StatusBarCompat.translucentStatusBar(activity) .changeToLightStatusBar(activity) .Demo 只有一个 Activity , 分四个 Tab.
setStatusBarColor.translucentStatusBar.setStatusBarColor.setStatusBarColorForCollapsingToolbar.这些问题仅仅出现在 4.4 上
StatusBarCompat.setStatusBarColor(Activity activity, int statusColor, int alpha) 方法, 推荐的透明值为 112.translucentStatusBar 方法时, 会给 Window 设置 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, 这个 Flag 和软键盘一起使用的时候可能会导致 AndroidBug5497, 可以尝试使用 这个方法 解决.在我的博客 Android-translucent-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.No open issues yet, or sync has not completed.