Marshmallow windowLightStatusBar = true 在 MI 中不工作 phone
Marshmallow windowLightStatusBar = true not working in MI phone
我想要白色状态栏,还想要默认颜色为深色的状态栏图标。但现在状态栏颜色是白色,但状态栏图标颜色没有更改为深色默认颜色。我的主题代码
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 phone 中无效。
<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);
它就像一个魅力。
来自文档 https://developer.android.com/reference/android/R.attr#windowLightStatusBar
For this to take effect, the window must be drawing the system bar backgrounds with windowDrawsSystemBarBackgrounds
and the status bar must not have been requested to be translucent with windowTranslucentStatus
我想要白色状态栏,还想要默认颜色为深色的状态栏图标。但现在状态栏颜色是白色,但状态栏图标颜色没有更改为深色默认颜色。我的主题代码
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 phone 中无效。
<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);
它就像一个魅力。
来自文档 https://developer.android.com/reference/android/R.attr#windowLightStatusBar
For this to take effect, the window must be drawing the system bar backgrounds with
windowDrawsSystemBarBackgrounds
and the status bar must not have been requested to be translucent withwindowTranslucentStatus