對安卓應用開發者,UI部分最難搞的就是APP頂部的狀態欄,
一致的APP風格,狀態欄僅僅需要設定一種顏色,
安卓全域顏色設定

單一APP狀態欄
很顯然,我們只要將AppTheme中colorPrimaryDark修改為APP設計中的統一風格即可,
動態修改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);
這樣就可以動態修改狀態欄背景顏色,
修改狀態欄圖示顏色
如果狀態欄背景修改為白色,那原來的狀態欄圖示豈不是都不可見了?
像這樣什么都看不到
將白色修改為黑色(PS.似乎只能是這兩種顏色)
Window window = getWindow();
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
如果需要將狀態欄圖示顏色動態修改為白色怎么處理呢?
getWindow().getDecorView().setSystemUiVisibility(0);
小米9SE測驗ok,至于其他的版本,請自行確認,
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/165240.html
標籤:python
