android oreo 触摸屏报点,androi 8.0 设置屏幕Orientation崩溃问题

博客主要围绕Android 8.0非不透明全屏设置屏幕方向崩溃问题展开。指出当AndroidManifest.xml中的activity同时设置android:windowIsTranslucent = true和android:screenOrientation=\portrait\会出现问题,并给出适配方案,还解析了不设置屏幕方向时方向的确定方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

android 8.0.。又名 android oreo

非不透明全屏,设置屏幕方向崩溃问题:

IllegalStateException: Only fullscreen opaque activities can request orientation

崩溃日志显示:只有全屏不透明的ac才能设置oritation

先看下示例,什么样的非全屏透明的ac就导致该崩溃了

1ed07ddbbbe5

example.jpeg

这非0即1的问题,没什么可研究的,适配一下:

1:true

android 8.0,在style中不能设置窗口半透明。所以,需要设置为false

1ed07ddbbbe5

translucent.png

2:manifest中,activity的屏幕方向去掉。

android:screenOrientation="portrait"

3:在ac中,oncreate函数中:处理兼容android 8.0以下版本

if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

}

简单几步,问题解决

1ed07ddbbbe5

halffinished.jpg

网上说这类解决方式的资料有很多,解决问题首要,再来了更深的了解一下该问题

解析:

该问题,主要就是AndroidManifest.xml中的activity同时设置

android:windowIsTranslucent = true

android:screenOrientation="portrait"

就会出现问题。

上面解决方案中去掉了设置screenOrientation,那么android 8.0中,不设置android:screenOrientation="portrait"。。那屏幕方向如何确定的?。。。。

in Android O, the translucent activity will have the same orientation as its parent activity

意思是说在android 8.0 中,当前ac会跟其上层ac一致。所以,示例中的弹框ac,没有设置oritation,但是其上层ac设置了。所以,没有问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值