今天在三星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