對安卓應用開發者,UI部分最難搞的就是APP頂部的狀態欄。
一致的APP風格,狀態欄僅僅須要設置一種顏色。
java
安卓全局顏色設置
單一APP狀態欄
很顯然,咱們只要將AppTheme中colorPrimaryDark修改成APP設計中的統一風格便可。android
動態修改APP狀態欄顏色
修改APP Theme
主要是window的一些配置佈局
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> <item name="android:windowNoTitle">true</item> <item name="windowNoTitle">true</item> <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">true</item> <item name="android:windowBackground">@android:color/holo_blue_bright</item> </style>
運行,看一下效果
狀態欄遮擋了APP"正文"
在activity佈局文件 根佈局添加
測試
android:fitsSystemWindows="true"
動態修改狀態欄背景顏色
getWindow().getDecorView().setBackgroundResource(android.R.color.holo_green_dark);
這樣就能夠動態修改狀態欄背景顏色。spa
修改狀態欄圖標顏色
若是狀態欄背景修改成白色,那原來的狀態欄圖標豈不是都不可見了?
像這樣什麼都看不到
設計
將白色修改成黑色(PS.彷佛只能是這兩種顏色)code
Window window = getWindow(); window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
若是須要將狀態欄圖標顏色動態修改成白色怎麼處理呢?blog
getWindow().getDecorView().setSystemUiVisibility(0);
小米9SE測試ok,至於其餘的版本,請自行確認。圖片