如何解决Android-在某些设备上全屏显示的奇怪工件
在Android 10模拟器和Galaxy S8物理设备(运行Android 9)上运行时,下一个代码可以正常运行。不过,在进入全屏模式的Motorola Moto G8(运行Android 9)上,所有视图的内容都会下降,并且会在状态栏位置显示空白黑色空间。
Galaxy G8,普通和全屏视图:
Motorola Moto G8,普通和全屏视图:
如您所见,在Motorola g8屏幕上,状态栏的尺寸减小,而在屏幕顶部则显示黑屏。
这是Android清单:
public class Sound {
private static SoundPool soundPool;
public short[] getSound(Activity activity,String...fileNames) {
soundPool = new SoundPool(10,AudioManager.STREAM_MUSIC,0);
short[] ids = new short[fileNames.length];
activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
try {
AssetManager assetManager = activity.getAssets();
for(int i = 0; i < fileNames.length; i++) {
AssetFileDescriptor descriptor = assetManager.openFd(fileNames[i]);
ids[i] = (short) soundPool.load(descriptor,1);
}
} catch(IOException e) {
//
}
return ids;
}
public void playSound(short id,float rV,float lV) {
if(id != -1) {
soundPool.play(id,rV,lV,1);
}
}
public void pauseSound() {
soundPool.autoPause();
}
public void releaseSound() {
soundPool.release();
}
}
这里是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>
活动类别:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:onClick="onButtonClick"
android:src="@drawable/llama" />
</RelativeLayout>
可以在Github上找到整个项目:https://github.com/alecpetrosky/Android-Immerse-Demo
解决方法
在函数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;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。