Android api27及以上“Only fullscreen opaque activities can request orientation”报错处理

记录自己开发遇到的问题,写的不好请见谅;

在适配到api27及以上时,有一个适配问题需要我们处理:

java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation

“fullscreen”为否的activity是不能锁定orientation的;

造成这个的原因是因为我们

在清单文件对应的activity中设置了: 

android:screenOrientation="portrait"

或者:

android:screenOrientation="landscape"

并且在style设置了样式属性:

<style name="NoTranslucent">

<item name="android:windowIsTranslucent">true</item>

</style>

我们自己写的activity,可以根据实际情况更改screenOrientation的值或者更改样式中不为透明;

当需要保留样式中的透明等设置时,可以使用android:screenOrientation="behind"替换原来的android:screenOrientation="portrait";

如果是集成三方的sdk的时候,可以用到一个新的属性:replace替换掉三方的属性,

<activity android:name=".TestActivity"
          android:screenOrientation="behind"
          tools:replace="screenOrientation"/>

以下是关于screenOrientation的一些附加介绍:

在配置文件中的使用方法如下:

<activity
            android:name=".App"
            android:label="@string/app_name"
            android:screenOrientation="portrait"//设置 该页面 只能 竖直屏幕方向显示 
            android:theme="@style/Theme.AppTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
</activity>
android:screenOrientation="" 这句话默认不写的话,其实就是android:screenOrientation="unspecified"
这是一个默认值,有系统选择显示方向,在不同的设备上可能结果不太一样.
android:screenOrientation="landscape"  横向屏幕
android:screenOrientation="portrait"   竖向屏幕
android:screenOrientation="user"       用户当前首选方向
android:screenOrientation="behind"     与在活动/Activity堆栈下的Activity方向相同
android:screenOrientation="sensor"     根据物理方向传感器 来确定方向,比如有的游戏既支持竖屏也支持横屏,取决于用户手持方向.
android:screenOrientation="nosensor"   不随 物理方向传感器确定方向,该传感器呗忽略,所以当用户转动设备,显示不会跟随改变.
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值