1

有些东西不起作用,我不知道这只是模拟器的问题还是它是Android Oreo中的错误(我没有Android O物理设备),但是我不能像Marschmallow那样从黑暗转变为光明状态栏主题。在Android上切换状态栏颜色的问题O

样式(从API 23):

<resources> 

    <style name="ThemeLight" parent="MyBaseTheme"> 
     <item name="android:windowBackground">?attr/colorPrimary</item> 
     <item name="android:statusBarColor">?attr/colorPrimary</item> 
     <item name="android:windowLightStatusBar">true</item> 
    </style> 


    <style name="ThemeDark" parent="MyBaseThemeDark"> 
     <item name="android:windowBackground">?attr/colorPrimary</item> 
     <item name="android:statusBarColor">?attr/colorPrimary</item> 
     <item name="android:windowLightStatusBar">false</item> 
    </style> 


</resources> 

在Android的棉花糖,当我更改主题与setTheme()工作正常,但在Android的O,一旦我切换到光的主题,它不再改变,状态栏保持黑暗(windowLightStatusBar = true)/:

回答

0

它必须是一个错误,并且我已经向Google(https://issuetracker.google.com/issues/65883460)报告了它。

我使用这些代码来临时解决问题。

// fix windowLightStatusBar not changed after applyStyle on Android O 
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 
    final TypedArray a = obtainStyledAttributes(new int[]{android.R.attr.windowLightStatusBar}); 
    final boolean windowLightStatusBar = a.getBoolean(0, false); 
    a.recycle(); 
    int flag = getWindow().getDecorView().getSystemUiVisibility(); 
    if (windowLightStatusBar) { 
     flag |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; 
    } else { 
     flag &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; 
    } 
    getWindow().getDecorView().setSystemUiVisibility(flag); 
}