今天总结一下状态栏的使用,当然也是参考别人的。但是总归自己得试试,然后把常用的几种情况记下来,因为这些东西是死的,下次拿过来就可以用。

一. 沉浸式状态栏  :Android 5.0以上才会支持沉浸式状态栏效果。 下面就建立一个默认的项目。1.状态栏(背景色是蓝色,字体图标是白色的)2.ActionBar,一般都不用的 3.内容 4.虚拟键。       所谓沉浸式状态栏就是只有3着哭泣区域占据整个屏幕,如爱奇艺全屏模式,玩王者荣耀的时候。但是一般情况下我们开发的APP都不会用到的,所以那里的沉浸式状态栏就是:去掉ActionBar,内容区占据状态栏(他俩重合),并且状态栏的透明或者半透明状态。行了直接上代码吧。

1.完全的沉浸式状态栏(下图):

代码:

@Override
public void onWindowFocusChanged(boolean hasFocus) {super.onWindowFocusChanged(hasFocus);if (hasFocus && Build.VERSION.SDK_INT >= 19) {View decorView = getWindow().getDecorView();decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION  | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION| View.SYSTEM_UI_FLAG_FULLSCREEN| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);}
}

图1

2.状态栏透明+底部导航栏透明+主体内容充满整个屏幕+去掉ActionBar(这种可以某些布局会影响操作  使用不多)

代码:

if (Build.VERSION.SDK_INT >= 21) {View decorView = getWindow().getDecorView();int option = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;decorView.setSystemUiVisibility(option);getWindow().setNavigationBarColor(Color.TRANSPARENT);getWindow().setStatusBarColor(Color.TRANSPARENT);
}
ActionBar actionBar = getSupportActionBar();
actionBar.hide();  

图2:

3.状态栏透明+主体内容上部延伸到状态栏+去掉ActionBar

代码:

if (Build.VERSION.SDK_INT >= 21) {View decorView = getWindow().getDecorView();int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;decorView.setSystemUiVisibility(option);getWindow().setStatusBarColor(Color.TRANSPARENT);
}
ActionBar actionBar = getSupportActionBar();
actionBar.hide();

图3.

注意: 1.使用沉浸式状态栏一定不要在Activity中的xml根布局中使用:

android:fitsSystemWindows="true"

2.如果不想在代码里面去掉ActionBar可以直接在style中修改Theme为:

parent="Theme.AppCompat.Light.NoActionBar"

二.如何修改状态栏的背景颜色和字体,图表颜色

1.状态栏字体颜色,我只接上工具类代码以及相关代码:

StateUtils:直接使用的工具类

SystemBarTintManager:修改状态颜色的辅助类
RomUtils:设置状态栏字体时候 怼不通机型进行适配

使用:

//设置状态蓝的颜色,也可以给颜色本身设置透明度,自己试试
StateUtils.setStatusBarColor(this, R.color.colorAccents);
//设置状态栏字体颜色,true:代表黑色,false代表白色
StateUtils.setLightStatusBar(this, true);
public class StateUtils {/*** 1.修改状态栏颜色,支持4.4以上版本* @param activity* @param colorId*/public static void setStatusBarColor(Activity activity, int colorId) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {Window window = activity.getWindow();window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);window.setStatusBarColor(activity.getResources().getColor(colorId));} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//使用SystemBarTint库使4.4版本状态栏变色,需要先将状态栏设置为透明transparencyBar(activity);SystemBarTintManager tintManager = new SystemBarTintManager(activity);tintManager.setStatusBarTintEnabled(true);tintManager.setStatusBarTintResource(colorId);}}/***  2.修改状态栏文字颜色,这里小米,魅族区别对待。*/public static void setLightStatusBar(final Activity activity, final boolean dark) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {switch (RomUtils.getLightStatusBarAvailableRomType()) {case RomUtils.AvailableRomType.MIUI:MIUISetStatusBarLightMode(activity, dark);break;case RomUtils.AvailableRomType.FLYME:setFlymeLightStatusBar(activity, dark);break;case RomUtils.AvailableRomType.ANDROID_NATIVE:setAndroidNativeLightStatusBar(activity, dark);break;}}}/*** 小米修改状态栏字体* @param activity* @param dark* @return*/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);//状态栏透明且黑色字体} else {extraFlagField.invoke(window, 0, darkModeFlag);//清除黑色字体}result = true;if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && RomUtils.isMiUIV7OrAbove()) {//开发版 7.7.13 及以后版本采用了系统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;}/*** 魅族修改字体颜色* @param activity* @param dark* @return*/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;}/*** 谷歌原生方式修改* @param activity* @param dark*/private static void setAndroidNativeLightStatusBar(Activity activity, boolean dark) {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);}}/*** 设置状态栏透明,启用全屏模式* @param activity*/@TargetApi(19)public static void transparencyBar(Activity activity) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {Window window = activity.getWindow();window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);window.setStatusBarColor(Color.TRANSPARENT);window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {Window window = activity.getWindow();window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);}}}
/*** Class to manage status and navigation bar tint effects when using KitKat* translucent system UI modes.* 修改状态栏颜色的辅助类 **/
public class SystemBarTintManager {static {// Android allows a system property to override the presence of the navigation bar.// Used by the emulator.// See https://github.com/android/platform_frameworks_base/blob/master/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java#L1076if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {try {Class c = Class.forName("android.os.SystemProperties");Method m = c.getDeclaredMethod("get", String.class);m.setAccessible(true);sNavBarOverride = (String) m.invoke(null, "qemu.hw.mainkeys");} catch (Throwable e) {sNavBarOverride = null;}}}/*** The default system bar tint color value.*/public static final int DEFAULT_TINT_COLOR = 0x99000000;private static String sNavBarOverride;private final SystemBarConfig mConfig;private boolean mStatusBarAvailable;private boolean mNavBarAvailable;private boolean mStatusBarTintEnabled;private boolean mNavBarTintEnabled;private View mStatusBarTintView;private View mNavBarTintView;/*** Constructor. Call this in the host activity onCreate method after its* content view has been set. You should always create new instances when* the host activity is recreated.** @param activity The host activity.*/@TargetApi(19)public SystemBarTintManager(Activity activity) {Window win = activity.getWindow();ViewGroup decorViewGroup = (ViewGroup) win.getDecorView();if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {// check theme attrsint[] attrs = {android.R.attr.windowTranslucentStatus,android.R.attr.windowTranslucentNavigation};TypedArray a = activity.obtainStyledAttributes(attrs);try {mStatusBarAvailable = a.getBoolean(0, false);mNavBarAvailable = a.getBoolean(1, false);} finally {a.recycle();}// check window flagsWindowManager.LayoutParams winParams = win.getAttributes();int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;if ((winParams.flags & bits) != 0) {mStatusBarAvailable = true;}bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;if ((winParams.flags & bits) != 0) {mNavBarAvailable = true;}}mConfig = new SystemBarConfig(activity, mStatusBarAvailable, mNavBarAvailable);// device might not have virtual navigation keysif (!mConfig.hasNavigtionBar()) {mNavBarAvailable = false;}if (mStatusBarAvailable) {setupStatusBarView(activity, decorViewGroup);}if (mNavBarAvailable) {setupNavBarView(activity, decorViewGroup);}}/*** Enable tinting of the system status bar.** If the platform is running Jelly Bean or earlier, or translucent system* UI modes have not been enabled in either the theme or via window flags,* then this method does nothing.** @param enabled True to enable tinting, false to disable it (default).*/public void setStatusBarTintEnabled(boolean enabled) {mStatusBarTintEnabled = enabled;if (mStatusBarAvailable) {mStatusBarTintView.setVisibility(enabled ? View.VISIBLE : View.GONE);}}/*** Enable tinting of the system navigation bar.** If the platform does not have soft navigation keys, is running Jelly Bean* or earlier, or translucent system UI modes have not been enabled in either* the theme or via window flags, then this method does nothing.** @param enabled True to enable tinting, false to disable it (default).*/public void setNavigationBarTintEnabled(boolean enabled) {mNavBarTintEnabled = enabled;if (mNavBarAvailable) {mNavBarTintView.setVisibility(enabled ? View.VISIBLE : View.GONE);}}/*** Apply the specified color tint to all system UI bars.** @param color The color of the background tint.*/public void setTintColor(int color) {setStatusBarTintColor(color);setNavigationBarTintColor(color);}/*** Apply the specified drawable or color resource to all system UI bars.** @param res The identifier of the resource.*/public void setTintResource(int res) {setStatusBarTintResource(res);setNavigationBarTintResource(res);}/*** Apply the specified drawable to all system UI bars.** @param drawable The drawable to use as the background, or null to remove it.*/public void setTintDrawable(Drawable drawable) {setStatusBarTintDrawable(drawable);setNavigationBarTintDrawable(drawable);}/*** Apply the specified alpha to all system UI bars.** @param alpha The alpha to use*/public void setTintAlpha(float alpha) {setStatusBarAlpha(alpha);setNavigationBarAlpha(alpha);}/*** Apply the specified color tint to the system status bar.** @param color The color of the background tint.*/public void setStatusBarTintColor(int color) {if (mStatusBarAvailable) {mStatusBarTintView.setBackgroundColor(color);}}/*** Apply the specified drawable or color resource to the system status bar.** @param res The identifier of the resource.*/public void setStatusBarTintResource(int res) {if (mStatusBarAvailable) {mStatusBarTintView.setBackgroundResource(res);}}/*** Apply the specified drawable to the system status bar.** @param drawable The drawable to use as the background, or null to remove it.*/@SuppressWarnings("deprecation")public void setStatusBarTintDrawable(Drawable drawable) {if (mStatusBarAvailable) {mStatusBarTintView.setBackgroundDrawable(drawable);}}/*** Apply the specified alpha to the system status bar.** @param alpha The alpha to use*/@TargetApi(11)public void setStatusBarAlpha(float alpha) {if (mStatusBarAvailable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {mStatusBarTintView.setAlpha(alpha);}}/*** Apply the specified color tint to the system navigation bar.** @param color The color of the background tint.*/public void setNavigationBarTintColor(int color) {if (mNavBarAvailable) {mNavBarTintView.setBackgroundColor(color);}}/*** Apply the specified drawable or color resource to the system navigation bar.** @param res The identifier of the resource.*/public void setNavigationBarTintResource(int res) {if (mNavBarAvailable) {mNavBarTintView.setBackgroundResource(res);}}/*** Apply the specified drawable to the system navigation bar.** @param drawable The drawable to use as the background, or null to remove it.*/@SuppressWarnings("deprecation")public void setNavigationBarTintDrawable(Drawable drawable) {if (mNavBarAvailable) {mNavBarTintView.setBackgroundDrawable(drawable);}}/*** Apply the specified alpha to the system navigation bar.** @param alpha The alpha to use*/@TargetApi(11)public void setNavigationBarAlpha(float alpha) {if (mNavBarAvailable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {mNavBarTintView.setAlpha(alpha);}}/*** Get the system bar configuration.** @return The system bar configuration for the current device configuration.*/public SystemBarConfig getConfig() {return mConfig;}/*** Is tinting enabled for the system status bar?** @return True if enabled, False otherwise.*/public boolean isStatusBarTintEnabled() {return mStatusBarTintEnabled;}/*** Is tinting enabled for the system navigation bar?** @return True if enabled, False otherwise.*/public boolean isNavBarTintEnabled() {return mNavBarTintEnabled;}private void setupStatusBarView(Context context, ViewGroup decorViewGroup) {mStatusBarTintView = new View(context);LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getStatusBarHeight());params.gravity = Gravity.TOP;if (mNavBarAvailable && !mConfig.isNavigationAtBottom()) {params.rightMargin = mConfig.getNavigationBarWidth();}mStatusBarTintView.setLayoutParams(params);mStatusBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);mStatusBarTintView.setVisibility(View.GONE);decorViewGroup.addView(mStatusBarTintView);}private void setupNavBarView(Context context, ViewGroup decorViewGroup) {mNavBarTintView = new View(context);LayoutParams params;if (mConfig.isNavigationAtBottom()) {params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getNavigationBarHeight());params.gravity = Gravity.BOTTOM;} else {params = new LayoutParams(mConfig.getNavigationBarWidth(), LayoutParams.MATCH_PARENT);params.gravity = Gravity.RIGHT;}mNavBarTintView.setLayoutParams(params);mNavBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);mNavBarTintView.setVisibility(View.GONE);decorViewGroup.addView(mNavBarTintView);}/*** Class which describes system bar sizing and other characteristics for the current* device configuration.**/public static class SystemBarConfig {private static final String STATUS_BAR_HEIGHT_RES_NAME = "status_bar_height";private static final String NAV_BAR_HEIGHT_RES_NAME = "navigation_bar_height";private static final String NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME = "navigation_bar_height_landscape";private static final String NAV_BAR_WIDTH_RES_NAME = "navigation_bar_width";private static final String SHOW_NAV_BAR_RES_NAME = "config_showNavigationBar";private final boolean mTranslucentStatusBar;private final boolean mTranslucentNavBar;private final int mStatusBarHeight;private final int mActionBarHeight;private final boolean mHasNavigationBar;private final int mNavigationBarHeight;private final int mNavigationBarWidth;private final boolean mInPortrait;private final float mSmallestWidthDp;private SystemBarConfig(Activity activity, boolean translucentStatusBar, boolean traslucentNavBar) {Resources res = activity.getResources();mInPortrait = (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);mSmallestWidthDp = getSmallestWidthDp(activity);mStatusBarHeight = getInternalDimensionSize(res, STATUS_BAR_HEIGHT_RES_NAME);mActionBarHeight = getActionBarHeight(activity);mNavigationBarHeight = getNavigationBarHeight(activity);mNavigationBarWidth = getNavigationBarWidth(activity);mHasNavigationBar = (mNavigationBarHeight > 0);mTranslucentStatusBar = translucentStatusBar;mTranslucentNavBar = traslucentNavBar;}@TargetApi(14)private int getActionBarHeight(Context context) {int result = 0;if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {TypedValue tv = new TypedValue();context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);result = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());}return result;}@TargetApi(14)private int getNavigationBarHeight(Context context) {Resources res = context.getResources();int result = 0;if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {if (hasNavBar(context)) {String key;if (mInPortrait) {key = NAV_BAR_HEIGHT_RES_NAME;} else {key = NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME;}return getInternalDimensionSize(res, key);}}return result;}@TargetApi(14)private int getNavigationBarWidth(Context context) {Resources res = context.getResources();int result = 0;if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {if (hasNavBar(context)) {return getInternalDimensionSize(res, NAV_BAR_WIDTH_RES_NAME);}}return result;}@TargetApi(14)private boolean hasNavBar(Context context) {Resources res = context.getResources();int resourceId = res.getIdentifier(SHOW_NAV_BAR_RES_NAME, "bool", "android");if (resourceId != 0) {boolean hasNav = res.getBoolean(resourceId);// check override flag (see static block)if ("1".equals(sNavBarOverride)) {hasNav = false;} else if ("0".equals(sNavBarOverride)) {hasNav = true;}return hasNav;} else { // fallbackreturn !ViewConfiguration.get(context).hasPermanentMenuKey();}}private int getInternalDimensionSize(Resources res, String key) {int result = 0;int resourceId = res.getIdentifier(key, "dimen", "android");if (resourceId > 0) {result = res.getDimensionPixelSize(resourceId);}return result;}@SuppressLint("NewApi")private float getSmallestWidthDp(Activity activity) {DisplayMetrics metrics = new DisplayMetrics();if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);} else {// TODO this is not correct, but we don't really care pre-kitkatactivity.getWindowManager().getDefaultDisplay().getMetrics(metrics);}float widthDp = metrics.widthPixels / metrics.density;float heightDp = metrics.heightPixels / metrics.density;return Math.min(widthDp, heightDp);}/*** Should a navigation bar appear at the bottom of the screen in the current* device configuration? A navigation bar may appear on the right side of* the screen in certain configurations.** @return True if navigation should appear at the bottom of the screen, False otherwise.*/public boolean isNavigationAtBottom() {return (mSmallestWidthDp >= 600 || mInPortrait);}/*** Get the height of the system status bar.** @return The height of the status bar (in pixels).*/public int getStatusBarHeight() {return mStatusBarHeight;}/*** Get the height of the action bar.** @return The height of the action bar (in pixels).*/public int getActionBarHeight() {return mActionBarHeight;}/*** Does this device have a system navigation bar?** @return True if this device uses soft key navigation, False otherwise.*/public boolean hasNavigtionBar() {return mHasNavigationBar;}/*** Get the height of the system navigation bar.** @return The height of the navigation bar (in pixels). If the device does not have* soft navigation keys, this will always return 0.*/public int getNavigationBarHeight() {return mNavigationBarHeight;}/*** Get the width of the system navigation bar when it is placed vertically on the screen.** @return The width of the navigation bar (in pixels). If the device does not have* soft navigation keys, this will always return 0.*/public int getNavigationBarWidth() {return mNavigationBarWidth;}/*** Get the layout inset for any system UI that appears at the top of the screen.** @param withActionBar True to include the height of the action bar, False otherwise.* @return The layout inset (in pixels).*/public int getPixelInsetTop(boolean withActionBar) {return (mTranslucentStatusBar ? mStatusBarHeight : 0) + (withActionBar ? mActionBarHeight : 0);}/*** Get the layout inset for any system UI that appears at the bottom of the screen.** @return The layout inset (in pixels).*/public int getPixelInsetBottom() {if (mTranslucentNavBar && isNavigationAtBottom()) {return mNavigationBarHeight;} else {return 0;}}/*** Get the layout inset for any system UI that appears at the right of the screen.** @return The layout inset (in pixels).*/public int getPixelInsetRight() {if (mTranslucentNavBar && !isNavigationAtBottom()) {return mNavigationBarWidth;} else {return 0;}}}
/*** 设置状态栏时候 怼不通机型进行适配*/
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() {//开发版 7.7.13 及以后版本采用了系统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";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;}}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;}}}

好了 ,也就这些了 。  自己可以复制出去试试就好了。

总结:

一般情况首页的那几个Fragment 使用的沉浸式较多一些:透明状态栏+黑色      或者透明状态栏+白色

业务模块中: 可以统一设置状态栏颜色,以及字体颜色。

状态栏总结(沉浸式状态栏+状态栏颜色+状态栏字体的颜色)相关推荐

  1. Android布局延伸状态栏,Android沉浸式全屏讲解(状态栏、导航栏处理)

    Android应用中经常会有一些要求全屏显隐状态栏导航栏的需求.通过全屏沉浸式的处理可以让应用达到更好的显示效果.下面系统的讲解一下有关全屏,隐藏状态栏导航栏,沉浸式的知识. 在Android4.1之 ...

  2. Android --- 详细介绍透明式状态栏和沉浸式状态栏

    今天来写一个类似于qq空间的那种沉浸式效果.先来看看qq空间的这种效果 我们看到,头部局上拉的时候有个头布局的透明是从0变化到1,当你下拉的时候,头部局透明度又从1变化到0了.始终效果看起来还是不错的 ...

  3. android 4.4 以上沉浸式状态栏和沉浸式导航栏管理,一句代码轻松实现

    ImmersionBar 项目地址:gyf-dev/ImmersionBar  简介:android 4.4 以上沉浸式状态栏和沉浸式导航栏管理,一句代码轻松实现,以及对 bar 的其他设置,详见 R ...

  4. android图片延伸到状态栏,Android 沉浸式状态栏的多种样式

    小菜最近正在处理客户端顶部沉浸式展示图片,借此整理了一下小菜自己研究测试的沉浸式状态栏. 沉浸式状态栏大家都很熟悉,即 APP 界面图片延伸到状态栏, 应用本身沉浸于状态栏,即顶部不会默认展示系统的黑 ...

  5. android透明度大全,状态栏大全-状态栏透明(沉浸式)、变色及全屏的区别

    手机的顶部状态栏,也就是信号.电量那条,有4种状态,分别是正常.变色.透明(也称沉浸式状态栏).消失(也就是全屏). 后3种特殊用法,具体见下: 状态栏变色 常见使用场景:如果title背景为纯色且显 ...

  6. android沉浸式模式简书,Android 沉浸式模式与常见状态栏和导航栏效果

    Android沉浸式模式 官方称沉浸式状态栏为沉浸式模式. 什么是沉浸式? 沉浸式就是让人专注当前的(由设计者营造)情境下感到愉悦和满足,而忘记真实的情境. 什么是Android中的沉浸式? 当启用该 ...

  7. android实现系统状态栏的隐藏方法,Android隐藏系统状态栏(沉浸式状态栏)和设置状态栏颜色...

    Android 5.0(API 21)之后就可以对系统状态栏进行设置了,这里我不是想深入讨论对系统状态栏的一些高级设置,因为一般也用不到,我只想说最常见的两种场景 隐藏系统状态栏,这就是感觉很牛逼的沉 ...

  8. android 沉浸式之改变小米状态栏颜色

    这个是基于SystemBarTintManager更改的 增加一个方法:用于更改MIUIV6系统上的状态栏字体颜色 ,目前我仅仅只发现MIUIV6上可以更改,在android5.0上以及其它4.4以上 ...

  9. android 沉浸式菜单栏,Android沉浸式全屏讲解(状态栏、导航栏处理)

    Android应用中经常会有一些要求全屏显隐状态栏导航栏的需求.通过全屏沉浸式的处理可以让应用达到更好的显示效果.下面系统的讲解一下有关全屏,隐藏状态栏导航栏,沉浸式的知识. 在Android4.1之 ...

  10. android状态栏一体化(沉浸式状态栏)

    Android 沉浸式状态栏.状态栏一体化.透明状态栏.仿ios透明状态栏 http://blog.csdn.net/jdsjlzx/article/details/50437779 注:状态栏的字体 ...

最新文章

  1. 第三节 MemcachedProviders之SesstionStateProvider(关于Session的讨论)
  2. php aws s3查看所有文件_国内AWS没有文件系统服务,快来看如何通过EC2挂载S3存储桶替代...
  3. 关于对象、构造函数、原型、原型链、继承
  4. java arraylist 函数_Java Extend ArrayList函数
  5. android 状态栏 背景色_技术一面:说说Android动态换肤实现原理
  6. x86架构和arm架构_RISC-V架构1000核CPU登场 x86架构腹背受敌
  7. beedb mysql_26.蛤蟆笔记go语言——beedb库使用
  8. python进阶16多继承与Mixin
  9. Flink_大数据技术之电商用户行为分析
  10. 常用电子元器件参考资料(参数手册大全)
  11. 3D游戏案例:滚动天空(超低配版)
  12. 3DMAX2020 材质编辑器为物理材质的问题
  13. python短信验证码登录_Python实现短信验证
  14. 慧正工作流注册码获取
  15. 输入快递单号查询不到物流怎么办
  16. Day.js 一个轻量级的 JavaScript 时间日期处理库
  17. Guava学习之Joiner
  18. C++创意编程——自制 gif 表情包
  19. 大数据环境下互联网行业数据仓库/数据平台的架构之漫谈
  20. Swift-自动引用计数(Automatic Reference Counting)(十四)

热门文章

  1. 微型计算机技术指标主要是,微型计算机主要技术指标
  2. 171103 逆向-内存与外挂(培训提纲)
  3. 红枣银耳汤的做法和功效
  4. validator-表单验证神器
  5. 自动驾驶不等于无人驾驶,无人驾驶的概念是什么
  6. 备赛电赛学习硬件篇(五):硬件框图、无线通信模块、OLED模块设计
  7. docker 部署portaine 容器管理
  8. python控制led屏_python轮询机制控制led实例
  9. 在云端的输入法:搜狗云引发下一代输入法革命
  10. java if 不加大括号_if条件后加大括号{}和不加大括号{}的区别