Android StatusBar 黑底白字
生活随笔
收集整理的這篇文章主要介紹了
Android StatusBar 黑底白字
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
· 引用gradle:
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'· 實現
public class StatusBar {//白色可以替換成其他淺色系@TargetApi(Build.VERSION_CODES.LOLLIPOP)public static void myStatusBar(Activity activity) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {if (MIUISetStatusBarLightMode(activity.getWindow(), true)) {//MIUIif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0activity.getWindow().setStatusBarColor(Color.WHITE);} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);SystemBarTintManager tintManager = new SystemBarTintManager(activity);tintManager.setStatusBarTintEnabled(true);tintManager.setStatusBarTintResource(android.R.color.white);}} else if (FlymeSetStatusBarLightMode(activity.getWindow(), true)) {//Flymeif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0activity.getWindow().setStatusBarColor(Color.WHITE);} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);SystemBarTintManager tintManager = new SystemBarTintManager(activity);tintManager.setStatusBarTintEnabled(true);tintManager.setStatusBarTintResource(android.R.color.white);}} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {//6.0activity.getWindow().setStatusBarColor(Color.WHITE);activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);}}}/*** 設置狀態欄字體圖標為深色,需要MIUIV6以上** @param window 需要設置的窗口* @param dark 是否把狀態欄字體及圖標顏色設置為深色* @return boolean 成功執行返回true*/public static boolean MIUISetStatusBarLightMode(Window window, boolean dark) {boolean result = false;if (window != null) {Class clazz = window.getClass();try {int darkModeFlag = 0;Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");darkModeFlag = field.getInt(layoutParams);Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);if (dark) {extraFlagField.invoke(window, darkModeFlag, darkModeFlag);//狀態欄透明且黑色字體} else {extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字體}result = true;} catch (Exception e) {}}return result;}/*** 設置狀態欄圖標為深色和魅族特定的文字風格* 可以用來判斷是否為Flyme用戶** @param window 需要設置的窗口* @param dark 是否把狀態欄字體及圖標顏色設置為深色* @return boolean 成功執行返回true*/public static boolean FlymeSetStatusBarLightMode(Window window, boolean dark) {boolean result = false;if (window != null) {try {WindowManager.LayoutParams lp = window.getAttributes();Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");darkFlag.setAccessible(true);meizuFlags.setAccessible(true);int bit = darkFlag.getInt(null);int value = meizuFlags.getInt(lp);if (dark) {value |= bit;} else {value &= ~bit;}meizuFlags.setInt(lp, value);window.setAttributes(lp);result = true;} catch (Exception e) {}}return result;}}· 效果
來自原文:http://www.jianshu.com/p/7d8df51347ff
總結
以上是生活随笔為你收集整理的Android StatusBar 黑底白字的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大学计算机基础操作教程文本框,大学计算机
- 下一篇: directx游戏开发终极指南 dire