9.0: WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; getWindow().setAttributes(lp); View decorView = getWindow().getDecorView(); int systemUiVisibility = decorView.getSystemUiVisibility(); int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION//隐藏导航栏 | View.SYSTEM_UI_FLAG_FULLSCREEN;//隐藏状态栏 systemUiVisibility |= flags; getWindow().getDecorView().setSystemUiVisibility(systemUiVisibility);
<style name="AppFullTheme" parent="AppTheme"> <item name="android:windowTranslucentNavigation">true</item> <item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item> <item name="android:windowFullscreen">true</item> </style>
9.0or其他以下:
WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; getWindow().setAttributes(attrs);