5.x環境下html
/** * 狀態欄相關工具類 * */ public class StatusBarUtils { public static void setWindowStatusBarColor(Activity activity, int colorResId) { try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = activity.getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(activity.getResources().getColor(colorResId)); //底部導航欄 //window.setNavigationBarColor(activity.getResources().getColor(colorResId)); } } catch (Exception e) { e.printStackTrace(); } } public static void setWindowStatusBarColor(Dialog dialog, int colorResId) { try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = dialog.getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(dialog.getContext().getResources().getColor(colorResId)); //底部導航欄 //window.setNavigationBarColor(activity.getResources().getColor(colorResId)); } } catch (Exception e) { e.printStackTrace(); } } }
windowTranslucentStatus=true
屬性。
<stylename="AppTheme"parent="Theme.AppCompat.Light.NoActionBar"> <itemname="colorPrimary">@android:color/holo_blue_bright</item> <itemname="colorPrimaryDark">@android:color/holo_blue_bright</item> </style>
<stylename="AppTheme"parent="@style/BaseAppTheme"> <itemname="android:windowTranslucentStatus">true</item> </style>
android:background="@android:color/holo_blue_bright"
android:fitsSystemWindows="true"