今天在三星S8上碰见一个奇葩问题Only fullscreen opaque activities can request orientation
java
manifest中移除android:screenOrientation="portrait"
android
查看Android 8.0源码app
有几个条件:google
!fullscreen
appInfo.targetSdkVersion > O
因此下边来跟踪一下ActivityInfo.isFixedOrientation(requestedOrientation)
spa
继续跟踪isFixedOrientationPortrait(int orientation)
设计
最后的缘由找到了,就是由于orientation == SCREEN_ORIENTATION_PORTRAIT
3d
targetSdkVersion>26
的Android AppAndroid 8.0(含) 以上
的设备上时透明Activity
时screenOrientation 需为默认状态code
在 stackoverflow 中看到一句话。cdn
这句话,我在google官方文档上并无找到依据,但通过个人验证是正确的
blog
If you use a fullscreen transparent activity, there is no need to specify the orientation lock on the activity. It will take the configuration settings of the parent activity. So if the parent activity has in the manifest:
这种状况下,透明Activity使用的是栈中,上一层可见Activity的orientation设定
。仔细想想是合理的,所以这并非一个bug。
android:screenOrientation="portrait"
的解决方案,彻底符合Google的设计本意,并不是Bug