android沉浸式状态栏总结

根据郭神公众号总结:

1、标题栏和状态栏保持一个颜色:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.L) {
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
}

2、使状态栏和标题栏保持一个颜色并且状态栏和底部虚拟按键在一定时间消失,需要在activity里面重写onWindowFocusChanged方法:

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus && Build.VERSION.SDK_INT >= 19) {
            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
                    View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
                    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                    View.SYSTEM_UI_FLAG_FULLSCREEN |
                    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            );
        }
    }

去掉标题栏ActionBar,在res/values/styles.xml文件中添加:

        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>

猜你喜欢

转载自blog.csdn.net/qq_34602140/article/details/81979502