您的位置:首页 > 移动开发 > Android开发

android 沉浸式

2016-05-09 14:30 393 查看
在android4.4以上,就可以进行沉浸式开发了,具体代码:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setTranslucentStatus(true);
}

SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintResource(R.color.appmain);//通知栏所需颜色

这是设置你的通知栏的颜色

然后要进行一个版本的判断:

@TargetApi(19)
private void setTranslucentStatus(boolean on) {
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);
}这样就可以变成沉浸式的了,但是你自己的app标题就会被半透明的通知栏覆盖一部分,这肯定不是我们想要的这时候就需要在我们的activity或者fragment中的xml的最外层的容器上加上两句话:
android:clipToPadding="true"
android:fitsSystemWindows="true"
这样就可以了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: