Android全屏 隐藏状态栏、标题栏和导航栏

最近项目中需要实现全屏,看了好几篇博客,最后调试结果如下:
1.在styles.xml中自定义主题样式隐藏actionBar:


然后在AndroidManifest.xml文件中的下配置

android:theme="@style/NoStatusTheme"

2.动态隐藏状态栏和标题栏:

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    hideSystemBar();// 全屏设置
    setContentView(R.layout.activity_home);
}

private void hideSystemBar(){
    if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) {
        View v = this.getWindow().getDecorView();
        v.setSystemUiVisibility(View.GONE);
    } else if (Build.VERSION.SDK_INT >= 19) {
        View decorView = getWindow().getDecorView();
        int uiOptions =
                View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
        decorView.setSystemUiVisibility(uiOptions);
    }
}

你可能感兴趣的:(Android全屏 隐藏状态栏、标题栏和导航栏)