日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android StatusBar 黑底白字

發(fā)布時間:2023/12/14 Android 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android StatusBar 黑底白字 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

· 引用gradle

compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'

· 實現(xiàn)

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);}}}/*** 設(shè)置狀態(tài)欄字體圖標(biāo)為深色,需要MIUIV6以上** @param window 需要設(shè)置的窗口* @param dark 是否把狀態(tài)欄字體及圖標(biāo)顏色設(shè)置為深色* @return boolean 成功執(zhí)行返回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);//狀態(tài)欄透明且黑色字體} else {extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字體}result = true;} catch (Exception e) {}}return result;}/*** 設(shè)置狀態(tài)欄圖標(biāo)為深色和魅族特定的文字風(fēng)格* 可以用來判斷是否為Flyme用戶** @param window 需要設(shè)置的窗口* @param dark 是否把狀態(tài)欄字體及圖標(biāo)顏色設(shè)置為深色* @return boolean 成功執(zhí)行返回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

總結(jié)

以上是生活随笔為你收集整理的Android StatusBar 黑底白字的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。