我试图设置状态栏颜色,但有不同的api级别的麻烦。
我想要黑暗的图标颜色和黄色背景。我已经设置了版本样式,但它没有为API Level 21设置。请看一下标有红色的屏幕截图。
这是代码
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/colorPrimaryBackground</item>
<item name="android:textColor">@color/colorPrimaryText</item>
<item name="android:windowLightStatusBar">true</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/colorPrimaryBackground</item>
<item name="android:textColor">@color/colorPrimaryText</item>
</style>
您想要做什么是api> 23尝试以下代码:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
View decor = getWindow().getDecorView();
if (shouldChangeStatusBarTintToDark) {
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
// We want to change tint color to white again.
// You can also record the flags in advance so that you can turn UI back completely if
// you have set other flags before, such as translucent or full screen.
decor.setSystemUiVisibility(0);
}
}