草庐IT

android - Marshmallow windowLightStatusBar = true 在 MI 手机中不工作

coder 2023-12-08 原文

我想要白色状态栏,还想要默认颜色为深色的状态栏图标。但现在状态栏颜色是白色,但状态栏图标颜色没有更改为深色默认颜色。我的主题代码

value-v23/styles.xml

<style name="AppTheme.NoActionBar">

        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowLightStatusBar">true</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/white</item>
    </style>

我将 windowLightStatusBar 设置为 true 它在所有设备上工作但在 MI 手机上不工作。

<item name="android:windowLightStatusBar">true</item>

我附上了 MI 设备和 intex 设备的屏幕截图。在 MI 设备状态栏图标中显示为白色,在 intex 设备中显示为深色默认颜色。

最佳答案

public static boolean setMiuiStatusBarDarkMode(Activity activity, boolean darkmode) {
    Class<? extends Window> clazz = activity.getWindow().getClass();
    try {
        int darkModeFlag = 0;
        Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
        Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
        darkModeFlag = field.getInt(layoutParams);
        Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
        extraFlagField.invoke(activity.getWindow(), darkmode ? darkModeFlag : 0, darkModeFlag);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

setMiuiStatusBarDarkMode(YourBaseActivity.this,true);

它就像一个魅力。

关于android - Marshmallow windowLightStatusBar = true 在 MI 手机中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43963206/

有关android - Marshmallow windowLightStatusBar = true 在 MI 手机中不工作的更多相关文章

随机推荐