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);
本文详细介绍了如何在Android设备上实现应用全屏显示,并针对刘海屏(即带有屏幕缺口的设备)进行布局适配。包括使用WindowManager.LayoutParams设置布局参数,调整系统UI可见性以隐藏导航栏和状态栏,以及在不同Android版本间(如9.0及其他以下版本)的差异处理。
979

被折叠的 条评论
为什么被折叠?



