浅谈Android沉浸式

所谓沉浸式就是你的内容要渗透到状态栏和底部的导航栏里,而不是简单的全屏。只有在Android 4.4及以上系统才支持沉浸式模式


image.png

状态栏: 显示网络电池等信息,但是背影要跟随自己的内容变化。
ActionBar:看情况而定,有时候侧滑效果是要显示toolbar。
导航栏:沉浸式状态下,也是要不显示的,只有用户触发才显示导航栏。

具体做法:

  protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = getWindow().getDecorView();
            int option =
                     View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    ;
            decorView.setSystemUiVisibility(option);
            getWindow().setNavigationBarColor(Color.TRANSPARENT);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();

        setContentView(R.layout.activity_main);



最后style里添加


        true
        true
        @android:color/transparent
        true

测试环境 米8 刘海屏 Android10


图片发自App

你可能感兴趣的:(浅谈Android沉浸式)