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); 
}