compile 'com.gyf.barlibrary:barlibrary:2.2.5'
1.修改Application使用的主题
修改方法:把本来继承Back什么换为NoActionBar
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowContentOverlay">@null</item>
</style>
2.xml中的修改
在显示内容的父布局前面,添加一个为界面的view。它的颜色随意
<View
android:id="@+id/top_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/gengray" />
3.使用方法。这里的颜色需要你手动设置成和ToolBar一样的颜色
//设置状态栏的颜色
ImmersionBar.with(this)
//这个的目的是规避状态栏和布局重叠
.statusBarView(R.id.top_view)
.statusBarColor(R.color.gengray)
//设置状态栏的字体为深色,因为设置颜色后状态栏的文字看不清楚
.statusBarDarkFont(true)
//设置字体颜色,特定机型上不能设置的解决
.flymeOSStatusBarFontColor(R.color.black)
.init();
https://github.com/gyf-dev/ImmersionBar