Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Marshmallow windowLightStatusBar = true not working in MI phone

I want white color status bar and also want status bar icon with dark default color. but right now status bar color is white but status bar icon color not changed to dark default color. 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 set windowLightStatusBar as true its working in all device but not working in MI phone.

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

i attached screenshot of MI device and intex device. in MI device status bar icon showing in white color and in intex device showing in dark default color.

like image 398
Hitesh Gehlot Avatar asked May 14 '17 11:05

Hitesh Gehlot


1 Answers

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.

like image 90
dcnh35 Avatar answered Oct 14 '22 00:10

dcnh35