记录自己开发遇到的问题,写的不好请见谅;
在适配到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" 不随 物理方向传感器确定方向,该传感器呗忽略,所以当用户转动设备,显示不会跟随改变.