Android狀態列顏色修改
阿新 • • 發佈:2019-02-07
/** * 狀態列相關工具類 * */ 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(); } } }
效果圖如下:狀態列被改成android.R.color.holo_blue_bright,標題欄顏色可以和狀態列一樣,EditText的輸入也沒有受影響