android KITKAT 状态栏颜色

来源:互联网 发布:大连知润信息科技骗局 编辑:程序博客网 时间:2024/05/16 17:30

在activity中oncreate()中添加initSystemBar()方法

@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);    }    protected int mSataeBarBackground=R.color.top_bar_normal_bg;    protected void initSystemBar() {        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {            setTranslucentStatus(true);            SystemBarTintManager tintManager = new SystemBarTintManager(this);            tintManager.setStatusBarTintEnabled(true);            tintManager.setStatusBarTintResource(mSataeBarBackground);        }    }

在ContentView的根视图中添加

        android:fitsSystemWindows="true"
在style.xml中添加

        <item name="android:windowTranslucentStatus">true</item>        <item name="android:windowTranslucentNavigation">true</item>




0 0
原创粉丝点击