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

android状态栏透明适配以及状态栏不占位置的问题

2017-05-20 11:43 483 查看
将状态栏设置成透明并且兼容android4.4版本,见一下代码

private void InitWindow() {

Window window = getWindow();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}

并且需要设置style    <item
name="android:windowTranslucentStatus">true</item>

这样设置之后发现状态栏不占位置了,在布局时很尴尬,需要用到在android studio中引用 

compile
'com.readystatesoftware.systembartint:systembartint:1.0.3'

详情可以见网址

 SystemBarTint地址: https://github.com/hexiaochun/SystemBarTint

此网址中有详细的介绍和说明

private void InitWindow() {

Window window = getWindow();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
// set a custom tint color for all system bars
tintManager.setTintColor(Color.parseColor("#EC3F53"));
}


修改之后这样基本就可以了,状态栏也会占位置,其中关于状态栏沉浸式还可以参考以下网址
http://www.open-open.com/lib/view/open1455584716230.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: