首页 > 代码库 > 安卓设置沉浸式状态栏
安卓设置沉浸式状态栏
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();
}
}
安卓设置沉浸式状态栏
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。