不同API级别的Android状态栏颜色

问题描述 投票:0回答:1

我试图设置状态栏颜色,但有不同的api级别的麻烦。

我想要黑暗的图标颜色和黄色背景。我已经设置了版本样式,但它没有为API Level 21设置。请看一下标有红色的屏幕截图。

enter image description here

这是代码

v23\styles.xml

<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>

Default styles.xml

<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>
android android-styles
1个回答
2
投票

您想要做什么是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);
 }
}
© www.soinside.com 2019 - 2024. All rights reserved.