少年击剑更吹箫,剑气箫心一例消。这篇文章主要讲述安卓设置沉浸式状态栏相关的知识,希望能为你提供帮助。
【安卓设置沉浸式状态栏】
if(Build.VERSION.SDK_INT > = Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
window.setNavigationBarColor(Color.TRANSPARENT);
}
setTitleBarColor(status_bar, R.color.new_login_colors);
/**
* @params status_bar 顶替状态栏的view
* @params color 状态栏颜色
*/
public void setTitleBarColor(View status_bar, int color) {
try {
// 设置View的高度,因为每个型号的手机状态栏高度都不相同
status_bar.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, ScreenUtils.getStatusHeight(this)));
// 判断SDK版本是否大于等于19,大于就让他显示,小于就要隐藏,不然低版本会多出来一个
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
setTranslucentStatus(true);
status_bar.setVisibility(View.VISIBLE);
} else {
status_bar.setVisibility(View.GONE);
}
// 为状态栏着色
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintResource(color);
} catch (Exception e) {
e.printStackTrace();
}
}
@TargetApi(19)
private void setTranslucentStatus(boolean on) {
try {
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
if (on) {
winParams.flags |= bits;
} else {
winParams.flags & = ~bits;
}
win.setAttributes(winParams);
} catch (Exception e) {
e.printStackTrace();
}
}
推荐阅读
- Android手机测试-ddms&monitor-抓crash,log
- 微商分红返利app平台开发
- Applied Nonparametric Statistics-lec3
- 小程序预售商城开发平台app
- Android-Android内容提供器之运行时权限
- 安卓新标准出台_告别乱弹窗_你的手机真会省电么()
- Android中的Handler
- Snappy数据压缩 配置到Hadoop
- Applied Nonparametric Statistics-lec2