Android 安卓-在某些设备上全屏显示的一个奇怪的人工制品
在Android 10 emulator和Galaxy S8物理设备(运行Android 9)上运行时,下一个代码工作得非常好。然而,在摩托罗拉Moto G8(运行Android 9)进入全屏模式时,所有视图的内容都会下降,出现空白的黑色状态栏 Galaxy G8,普通和全屏视图: 摩托罗拉Moto G8,普通和全屏视图: 正如你所看到的,摩托罗拉g8的屏幕缩小了状态栏的大小,屏幕顶部出现了空白的黑屏 以下是Android清单:Android 安卓-在某些设备上全屏显示的一个奇怪的人工制品,android,android-activity,android-theme,android-statusbar,android-fullscreen,Android,Android Activity,Android Theme,Android Statusbar,Android Fullscreen,在Android 10 emulator和Galaxy S8物理设备(运行Android 9)上运行时,下一个代码工作得非常好。然而,在摩托罗拉Moto G8(运行Android 9)进入全屏模式时,所有视图的内容都会下降,出现空白的黑色状态栏 Galaxy G8,普通和全屏视图: 摩托罗拉Moto G8,普通和全屏视图: 正如你所看到的,摩托罗拉g8的屏幕缩小了状态栏的大小,屏幕顶部出现了空白的黑屏 以下是Android清单: android:theme="@style/A
android:theme="@style/AppTheme"
下面是styles.xml
:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<!--Required Api 21 above-->
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>
整个项目可在Github上获得:在函数setContentView之后添加以下代码
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}
在函数setContentView之后添加以下代码
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}
非常感谢,它解决了问题。我会给你们演示项目的学分。谢谢。我在等你,非常感谢,它解决了问题。我会给你们演示项目的学分。谢谢。我在等你
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}