1:全屏模式:
没有状态栏,就style里面设置就行了
<style name="AppTheme.FullBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@android:color/transparent</item>
<item name="android:windowBackground">@color/white</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowIsTranslucent">true</item>
</style>
2:沉浸式1:
没有有状态栏,但是状态栏上的字显示着,代码有点多
style代码:
<style name="WhiteAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="windowNoTitle">true</item>
<item name="android:windowActionBar">@null</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/transparent</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/white</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:screenOrientation">portrait</item>
<item name="android:windowIsTranslucent">true</item>
<item name="actionMenuTextColor">@color/colorPrimary</item>
</style>
然后在setContentView前设置一句
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
样式:
3:沉浸式2:
有状态栏,有显示文字
style代码:
<style name="WhiteAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="windowNoTitle">true</item>
<item name="android:windowActionBar">@null</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/transparent</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/white</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:screenOrientation">portrait</item>
<item name="android:windowIsTranslucent">true</item>
<item name="actionMenuTextColor">@color/colorPrimary</item>
</style>
其实和上面那个的style一样的,只是状态栏的颜色是这里面的android:windowBackground参数,只是少了在setContentView前设置的一句代码
样式:
动态设置状态栏颜色
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.statusBarColor = ContextCompat.getColor(this , color)//color是@color/white这种的
动态设置状态栏字体颜色
/**
* 改变状态栏字体颜色,白色和黑色两种
* @param update
* true:深色,false:浅色
*/
protected fun changeStatusBarTxtColor(update : Boolean) {
var originFlag = window.decorView.systemUiVisibility
if (update) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) window.decorView.systemUiVisibility = originFlag or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
}
window.decorView.findViewById<FrameLayout>(android.R.id.content).setPadding(0 , 0 , 0 , 0)
}