下面列出了android.view.View#SYSTEM_UI_FLAG_VISIBLE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Hide bar.
* 隐藏或显示状态栏和导航栏。
*
* @param uiFlags the ui flags
* @return the int
*/
@SuppressLint("ObsoleteSdkInt")
private int hideBar(int uiFlags) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
switch (mBarParams.barHide) {
case FLAG_HIDE_BAR:
uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.INVISIBLE;
break;
case FLAG_HIDE_STATUS_BAR:
uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.INVISIBLE;
break;
case FLAG_HIDE_NAVIGATION_BAR:
uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
break;
case FLAG_SHOW_BAR:
uiFlags |= View.SYSTEM_UI_FLAG_VISIBLE;
break;
}
}
return uiFlags | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
@UiThread
public void showSystemUI() {
cancelHideSystemUIDelayed();
toolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator()).start();
int flags = 0;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
flags = View.SYSTEM_UI_FLAG_VISIBLE;
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
}
getWindow().getDecorView().setSystemUiVisibility(flags);
}
/**
* Constructor not intended to be called by clients. Use
* {@link SystemUiHider#getInstance} to obtain an instance.
*/
protected SystemUiHiderHoneycomb(Activity activity, View anchorView, int flags) {
super(activity, anchorView, flags);
mShowFlags = View.SYSTEM_UI_FLAG_VISIBLE;
mHideFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
mTestFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
if ((mFlags & FLAG_FULLSCREEN) != 0) {
// If the client requested fullscreen, add flags relevant to hiding
// the status bar. Note that some of these constants are new as of
// API 16 (Jelly Bean). It is safe to use them, as they are inlined
// at compile-time and do nothing on pre-Jelly Bean devices.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if ((mFlags & FLAG_HIDE_NAVIGATION) != 0) {
// If the client requested hiding navigation, add relevant flags.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
mTestFlags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
}
/**
* Constructor not intended to be called by clients. Use
* {@link SystemUiHider#getInstance} to obtain an instance.
*/
protected SystemUiHiderHoneycomb(Activity activity, View anchorView, int flags) {
super(activity, anchorView, flags);
mShowFlags = View.SYSTEM_UI_FLAG_VISIBLE;
mHideFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
mTestFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
if ((mFlags & FLAG_FULLSCREEN) != 0) {
// If the client requested fullscreen, add flags relevant to hiding
// the status bar. Note that some of these constants are new as of
// API 16 (Jelly Bean). It is safe to use them, as they are inlined
// at compile-time and do nothing on pre-Jelly Bean devices.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if ((mFlags & FLAG_HIDE_NAVIGATION) != 0) {
// If the client requested hiding navigation, add relevant flags.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
mTestFlags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
}
/**
* Constructor not intended to be called by clients. Use
* {@link SystemUiHider#getInstance} to obtain an instance.
*/
protected SystemUiHiderHoneycomb(Activity activity, View anchorView, int flags) {
super(activity, anchorView, flags);
mShowFlags = View.SYSTEM_UI_FLAG_VISIBLE;
mHideFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
mTestFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
if ((mFlags & FLAG_FULLSCREEN) != 0) {
// If the client requested fullscreen, add flags relevant to hiding
// the status bar. Note that some of these constants are new as of
// API 16 (Jelly Bean). It is safe to use them, as they are inlined
// at compile-time and do nothing on pre-Jelly Bean devices.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if ((mFlags & FLAG_HIDE_NAVIGATION) != 0) {
// If the client requested hiding navigation, add relevant flags.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
mTestFlags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
}
/**
* Constructor not intended to be called by clients. Use
* {@link SystemUiHider#getInstance} to obtain an instance.
*/
protected SystemUiHiderHoneycomb(Activity activity, View anchorView, int flags) {
super(activity, anchorView, flags);
mShowFlags = View.SYSTEM_UI_FLAG_VISIBLE;
mHideFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
mTestFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
if ((mFlags & FLAG_FULLSCREEN) != 0) {
// If the client requested fullscreen, add flags relevant to hiding
// the status bar. Note that some of these constants are new as of
// API 16 (Jelly Bean). It is safe to use them, as they are inlined
// at compile-time and do nothing on pre-Jelly Bean devices.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if ((mFlags & FLAG_HIDE_NAVIGATION) != 0) {
// If the client requested hiding navigation, add relevant flags.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
mTestFlags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
}
/**
* Hide bar.
* 隐藏或显示状态栏和导航栏。
*
* @param uiFlags the ui flags
* @return the int
*/
private int hideBar(int uiFlags) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
switch (mBarParams.barHide) {
case FLAG_HIDE_BAR:
uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.INVISIBLE;
break;
case FLAG_HIDE_STATUS_BAR:
uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.INVISIBLE;
break;
case FLAG_HIDE_NAVIGATION_BAR:
uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
break;
case FLAG_SHOW_BAR:
uiFlags |= View.SYSTEM_UI_FLAG_VISIBLE;
break;
default:
break;
}
}
return uiFlags | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
/**
* Constructor not intended to be called by clients. Use
* {@link SystemUiHider#getInstance} to obtain an instance.
*/
protected SystemUiHiderHoneycomb(Activity activity, View anchorView, int flags) {
super(activity, anchorView, flags);
mShowFlags = View.SYSTEM_UI_FLAG_VISIBLE;
mHideFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
mTestFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
if ((mFlags & FLAG_FULLSCREEN) != 0) {
// If the client requested fullscreen, add flags relevant to hiding
// the status bar. Note that some of these constants are new as of
// API 16 (Jelly Bean). It is safe to use them, as they are inlined
// at compile-time and do nothing on pre-Jelly Bean devices.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if ((mFlags & FLAG_HIDE_NAVIGATION) != 0) {
// If the client requested hiding navigation, add relevant flags.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
mTestFlags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
}
/**
* Constructor not intended to be called by clients. Use {@link SystemUiHider#getInstance} to
* obtain an instance.
*/
protected SystemUiHiderHoneycomb(Activity activity, View anchorView, int flags) {
super(activity, anchorView, flags);
mShowFlags = View.SYSTEM_UI_FLAG_VISIBLE;
mHideFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
mTestFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
if ((mFlags & FLAG_FULLSCREEN) != 0) {
// If the client requested fullscreen, add flags relevant to hiding
// the status bar. Note that some of these constants are new as of
// API 16 (Jelly Bean). It is safe to use them, as they are inlined
// at compile-time and do nothing on pre-Jelly Bean devices.
mShowFlags |= 0x00000400;// View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
mHideFlags |= 0x00000400 //View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| 0x00000004; // View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if ((mFlags & FLAG_HIDE_NAVIGATION) != 0) {
// If the client requested hiding navigation, add relevant flags.
mShowFlags |= 0x00000200;//View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
mHideFlags |= 0x00000200//View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| 0x00000002;//View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
mTestFlags |= 0x00000002;//View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
}
/**
* Constructor not intended to be called by clients. Use
* {@link SystemUiHider#getInstance} to obtain an instance.
*/
protected SystemUiHiderHoneycomb(Activity activity, View anchorView, int flags) {
super(activity, anchorView, flags);
mShowFlags = View.SYSTEM_UI_FLAG_VISIBLE;
mHideFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
mTestFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
if ((mFlags & FLAG_FULLSCREEN) != 0) {
// If the client requested fullscreen, add flags relevant to hiding
// the status bar. Note that some of these constants are new as of
// API 16 (Jelly Bean). It is safe to use them, as they are inlined
// at compile-time and do nothing on pre-Jelly Bean devices.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if ((mFlags & FLAG_HIDE_NAVIGATION) != 0) {
// If the client requested hiding navigation, add relevant flags.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
mTestFlags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
}
/**
* Constructor not intended to be called by clients. Use
* {@link com.tudorluca.lantern.utils.SystemUiHider#getInstance} to obtain an instance.
*/
protected SystemUiHiderHoneycomb(Activity activity, View anchorView, int flags) {
super(activity, anchorView, flags);
mShowFlags = View.SYSTEM_UI_FLAG_VISIBLE;
mHideFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
mTestFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
if ((mFlags & FLAG_FULLSCREEN) != 0) {
// If the client requested fullscreen, add flags relevant to hiding
// the status bar. Note that some of these constants are new as of
// API 16 (Jelly Bean). It is safe to use them, as they are inlined
// at compile-time and do nothing on pre-Jelly Bean devices.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if ((mFlags & FLAG_HIDE_NAVIGATION) != 0) {
// If the client requested hiding navigation, add relevant flags.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
mTestFlags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
}
/**
* Android 6.0使用原始的主题适配
*
* @param activity Activity
* @param darkMode 是否是黑色模式
*/
public static void setBarDarkMode(Activity activity, boolean darkMode) {
Window window = activity.getWindow();
if (window == null) {
return;
}
//设置StatusBar模式
if (darkMode) {//黑色模式
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {//设置statusBar和navigationBar为黑色
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {//设置statusBar为黑色
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
}
} else {//白色模式
int statusBarFlag = View.SYSTEM_UI_FLAG_VISIBLE;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
statusBarFlag = window.getDecorView().getSystemUiVisibility()
& ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {//设置statusBar为白色,navigationBar为灰色
// int navBarFlag = window.getDecorView().getSystemUiVisibility()
// & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;//如果想让navigationBar为白色,那么就使用这个代码。
int navBarFlag = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
window.getDecorView().setSystemUiVisibility(navBarFlag | statusBarFlag);
} else {
window.getDecorView().setSystemUiVisibility(statusBarFlag);
}
}
setHuaWeiStatusBar(darkMode, window);
}
/**
* Constructor not intended to be called by clients. Use
* {@link SystemUiHider#getInstance} to obtain an instance.
*/
protected SystemUiHiderHoneycomb(Activity activity, View anchorView,
int flags) {
super(activity, anchorView, flags);
mShowFlags = View.SYSTEM_UI_FLAG_VISIBLE;
mHideFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
mTestFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
if ((mFlags & FLAG_FULLSCREEN) != 0) {
// If the client requested fullscreen, add flags relevant to hiding
// the status bar. Note that some of these constants are new as of
// API 16 (Jelly Bean). It is safe to use them, as they are inlined
// at compile-time and do nothing on pre-Jelly Bean devices.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if ((mFlags & FLAG_HIDE_NAVIGATION) != 0) {
// If the client requested hiding navigation, add relevant flags.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
mTestFlags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
}
/**
* Constructor not intended to be called by clients. Use
* {@link SystemUiHider#getInstance} to obtain an instance.
*/
protected SystemUiHiderHoneycomb(Activity activity, View anchorView,
int flags) {
super(activity, anchorView, flags);
mShowFlags = View.SYSTEM_UI_FLAG_VISIBLE;
//geändert zugunsten des Platzes...
//mShowFlags = View.SYSTEM_UI_FLAG_FULLSCREEN;
mHideFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
mTestFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
if ((mFlags & FLAG_FULLSCREEN) != 0) {
// If the client requested fullscreen, add flags relevant to hiding
// the status bar. Note that some of these constants are new as of
// API 16 (Jelly Bean). It is safe to use them, as they are inlined
// at compile-time and do nothing on pre-Jelly Bean devices.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if ((mFlags & FLAG_HIDE_NAVIGATION) != 0) {
// If the client requested hiding navigation, add relevant flags.
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
mTestFlags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
}
/**
* 打开状态栏,同样API16以上适用
*
* @param activity
*/
public static void showStatusBar(Activity activity) {
if (Build.VERSION.SDK_INT < 16) {
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
View decorView = activity.getWindow().getDecorView();
// Show Status Bar.
int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
decorView.setSystemUiVisibility(uiOptions);
}
}
@Override
protected int createShowFlags() {
return View.SYSTEM_UI_FLAG_VISIBLE;
}
@Override
protected int createShowFlags() {
return View.SYSTEM_UI_FLAG_VISIBLE;
}
private void positionAt(int x, int y) {
if (mRawPositionX == x && mRawPositionY == y) return;
mRawPositionX = x;
mRawPositionY = y;
final View contentView = mContainer.getContentView();
final int width = contentView.getMeasuredWidth();
final int height = contentView.getMeasuredHeight();
int positionX = (int) (x - width / 2.0f);
int positionY = y - height - mLineOffsetY;
int minOffsetY = 0;
if (mParent.getSystemUiVisibility() == View.SYSTEM_UI_FLAG_VISIBLE) {
minOffsetY = mStatusBarHeight;
}
final int screenWidth = mContext.getResources().getDisplayMetrics().widthPixels;
if (positionY < minOffsetY) {
// Vertical clipping, move under edited line and to the side of insertion cursor
// TODO bottom clipping in case there is no system bar
positionY += height;
positionY += mLineOffsetY;
// Move to right hand side of insertion cursor by default. TODO RTL text.
final int handleHalfWidth = mWidthOffsetX / 2;
if (x + width < screenWidth) positionX += handleHalfWidth + width / 2;
else positionX -= handleHalfWidth + width / 2;
} else {
// Horizontal clipping
positionX = Math.max(0, positionX);
positionX = Math.min(screenWidth - width, positionX);
}
// Offseting with location in window.
final int[] coords = new int[2];
mParent.getLocationInWindow(coords);
positionX += coords[0];
positionY += coords[1];
mContainer.showAtLocation(mParent, Gravity.NO_GRAVITY, positionX, positionY);
}
public static void setStatusBar(Activity activity, int bgColor, boolean isFullScreen, boolean isDarkStatusBarIcon) {
//5.0以下不处理
if (Build.VERSION.SDK_INT < 21) {
return;
}
int option = 0;
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//只有在6.0以上才改变状态栏颜色,否则在5.0机器上,电量条图标是白色的,标题栏也是白色的,就看不见电量条了了
//在5.0上显示默认灰色背景色
if (Build.VERSION.SDK_INT >= 23) {
// 设置状态栏底色颜色
activity.getWindow().setStatusBarColor(bgColor);
//浅色状态栏,则让状态栏图标变黑,深色状态栏,则让状态栏图标变白
if (isDarkStatusBarIcon) {
if (isFullScreen) {
option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
} else {
option = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
}
} else {
if (isFullScreen) {
option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_VISIBLE;
} else {
option = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_VISIBLE;
}
}
} else {
if (isFullScreen) {
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
} else {
activity.getWindow().setStatusBarColor(bgColor);
option = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
}
}
activity.getWindow().getDecorView().setSystemUiVisibility(option);
}
public static void setStatusBar(Activity activity, int bgColor, boolean isFullScreen, boolean isDarkStatusBarIcon) {
//5.0以下不处理
if (Build.VERSION.SDK_INT < 21) {
return;
}
int option = 0;
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//只有在6.0以上才改变状态栏颜色,否则在5.0机器上,电量条图标是白色的,标题栏也是白色的,就看不见电量条了了
//在5.0上显示默认灰色背景色
if (Build.VERSION.SDK_INT >= 23) {
// 设置状态栏底色颜色
activity.getWindow().setStatusBarColor(bgColor);
//浅色状态栏,则让状态栏图标变黑,深色状态栏,则让状态栏图标变白
if (isDarkStatusBarIcon) {
if (isFullScreen) {
option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
} else {
option = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
}
} else {
if (isFullScreen) {
option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_VISIBLE;
} else {
option = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_VISIBLE;
}
}
} else {
if (isFullScreen) {
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
} else {
activity.getWindow().setStatusBarColor(bgColor);
option = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
}
}
activity.getWindow().getDecorView().setSystemUiVisibility(option);
}