android 修改狀態列顏色
5.x環境下
方式一,狀態列將顯示為純淨的顏色,沒有漸變效果1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/**
*
狀態列相關工具類
*
*/
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
屬性。
方式二:
通過Style來修改狀態列顏色。
1.設定 colorPrimary,colorPrimaryDark兩個顏色。
1 2 3 4 |
< stylename ="AppTheme"parent="Theme.AppCompat.Light.NoActionBar">
< itemname ="colorPrimary">@android:color/holo_blue_bright</ item >
< itemname ="colorPrimaryDark">@android:color/holo_blue_bright</ item >
</ style >
|
1 2 3 |
< stylename ="AppTheme"parent="@style/BaseAppTheme">
< itemname ="android:windowTranslucentStatus">true</ item
|