package com.jyds.medic.util;
import android.app.Activity;
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import java.io.File;
import java.io.FileInputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Properties;
public class RomUtils {
class AvailableRomType {
public static final int MIUI = 1;
public static final int FLYME = 2;
public static final int ANDROID_NATIVE = 3;//安卓原生
public static final int NA = 4;
}
public static int getLightStatusBarAvailableRomType() {
//開發(fā)版 7.7.13 及以后版本采用了系統(tǒng)API,舊方法無效但不會報錯
if (isMiUIV7OrAbove()) {
return AvailableRomType.ANDROID_NATIVE;
}
if (isMiUIV6OrAbove()) {
return AvailableRomType.MIUI;
}
if (isFlymeV4OrAbove()) {
return AvailableRomType.FLYME;
}
if (isAndroidMOrAbove()) {
return AvailableRomType.ANDROID_NATIVE;
}
return AvailableRomType.NA;
}
//Flyme V4的displayId格式為 [Flyme OS 4.x.x.xA]
//Flyme V5的displayId格式為 [Flyme 5.x.x.x beta]
private static boolean isFlymeV4OrAbove() {
String displayId = Build.DISPLAY;
if (!TextUtils.isEmpty(displayId) && displayId.contains("Flyme")) {
String[] displayIdArray = displayId.split(" ");
for (String temp : displayIdArray) {
//版本號4以上厕吉,形如4.x.
if (temp.matches("^[4-9]\\.(\\d+\\.)+\\S*")) {
return true;
}
}
}
return false;
}
//Android Api 23以上
private static boolean isAndroidMOrAbove() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
}
private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";
//小米系統(tǒng)判斷
private static boolean isMiUIV6OrAbove() {
try {
final Properties properties = new Properties();
properties.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));
String uiCode = properties.getProperty(KEY_MIUI_VERSION_CODE, null);
if (uiCode != null) {
int code = Integer.parseInt(uiCode);
return code >= 4;
} else {
return false;
}
} catch (final Exception e) {
return false;
}
}
//小米系統(tǒng)判斷
static boolean isMiUIV7OrAbove() {
try {
final Properties properties = new Properties();
properties.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));
String uiCode = properties.getProperty(KEY_MIUI_VERSION_CODE, null);
if (uiCode != null) {
int code = Integer.parseInt(uiCode);
return code >= 5;
} else {
return false;
}
} catch (final Exception e) {
return false;
}
}
//小米系統(tǒng)下狀態(tài)欄文字顏色的修改
public static boolean MIUISetStatusBarLightMode(Activity activity, boolean dark) {
boolean result = false;
Window window = activity.getWindow();
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;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && RomUtils.isMiUIV7OrAbove()) {
//開發(fā)版 7.7.13 及以后版本采用了系統(tǒng)API,舊方法無效但不會報錯,所以兩個方式都要加上
if (dark) {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
}
} catch (Exception e) {
}
}
return result;
}
//魅族系統(tǒng)狀態(tài)欄文字顏色修改
private static boolean setFlymeLightStatusBar(Activity activity, boolean dark) {
boolean result = false;
if (activity != null) {
try {
WindowManager.LayoutParams lp = activity.getWindow().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);
activity.getWindow().setAttributes(lp);
result = true;
} catch (Exception e) {
}
}
return result;
}
public static void setActionBar(Activity activity,boolean dark){
int lightType = getLightStatusBarAvailableRomType();
if (lightType == AvailableRomType.ANDROID_NATIVE || lightType == AvailableRomType.NA) {
View decor = activity.getWindow().getDecorView();
if (dark) {
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
} else if (lightType == AvailableRomType.MIUI) {
MIUISetStatusBarLightMode(activity,true);
}else if (lightType == AvailableRomType.FLYME) {
setFlymeLightStatusBar(activity,true);
}
}
}
安卓手機(jī)上面的狀態(tài)欄的字體顏色設(shè)置
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門究履,熙熙樓的掌柜王于貴愁眉苦臉地迎上來滤否,“玉大人,你說我怎么就攤上這事最仑∶臧常” “怎么了炊甲?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀的道長欲芹。 經(jīng)常有香客問我卿啡,道長,這世上最難降的妖魔是什么菱父? 我笑而不...
- 正文 為了忘掉前任颈娜,我火速辦了婚禮,結(jié)果婚禮上滞伟,老公的妹妹穿的比我還像新娘揭鳞。我一直安慰自己,他們只是感情好梆奈,可當(dāng)我...
- 文/花漫 我一把揭開白布野崇。 她就那樣靜靜地躺著,像睡著了一般亩钟。 火紅的嫁衣襯著肌膚如雪乓梨。 梳的紋絲不亂的頭發(fā)上,一...
- 文/蒼蘭香墨 我猛地睜開眼蝠筑,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了揩懒?” 一聲冷哼從身側(cè)響起什乙,我...
- 正文 年R本政府宣布遭笋,位于F島的核電站坝冕,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏瓦呼。R本人自食惡果不足惜喂窟,卻給世界環(huán)境...
- 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望央串。 院中可真熱鬧磨澡,春花似錦、人聲如沸质和。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽饲宿。三九已至厦酬,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間瘫想,已是汗流浹背仗阅。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 一、導(dǎo)航欄屬性設(shè)置 二馒吴、設(shè)置狀態(tài)欄文字顏色第一步:在Info.plist中設(shè)置UIViewControllerBa...
- 1. 在ios9之前 [UIApplication sharedApplication].statusBarSty...