Marshmallow windowLightStatusBar = true does not work on MI phone

I need a status bar in white, as well as a status icon with a dark color by default. but now the color of the status bar is white, but the color of the status bar icon is not changed to dark by default. my theme code

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>

i sets windowLightStatusBar to true, works on the entire device, but does not work on the MI phone.

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

i includes a screenshot of the MI device and intex device. in the status icon of the MI device displayed in white, and in the intex device displayed in dark by default.

pWtWx.pngjnk2x.png

+4
source share
1 answer
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);

It works like a charm.

+9
source

Source: https://habr.com/ru/post/1677107/


All Articles