今天在三星S8上遇见一个奇葩问题Only fullscreen opaque activities can request orientation
manifest中移除android:screenOrientation="portrait"
查看Android 8.0源码
有几个条件:
!fullscreen
appInfo.targetSdkVersion > O
所以下边来跟踪一下ActivityInfo.isFixedOrientation(requestedOrientation)
继续跟踪isFixedOrientationPortrait(int orientation)
最后的原因找到了,就是因为orientation == SCREEN_ORIENTATION_PORTRAIT
targetSdkVersion>26
的Android AppAndroid 8.0(含) 以上
的设备上时透明Activity
时screenOrientation 需为默认状态
在 stackoverflow 中看到一句话。
这句话,我在google官方文档上并没有找到依据,但经过我的验证是正确的
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的设计本意,并非BugOnly fullscreen opaque activities can request orientation 原因及解决方案
原文:https://www.cnblogs.com/xiaxveliang/p/12396098.html