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

来源:互联网 发布:万达的管理模式知乎 编辑:程序博客网 时间:2024/06/06 01:11

将状态栏设置成透明并且兼容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    <itemname="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





原创粉丝点击