Only fullscreen opaque activities can request orientation错误记录

2022-07-26,,

当 三个条件同时满足的时候,系统会抛出"Only fullscreen activities can request orientation"异常。先分别来说说这三个条件都表示什么意思:

ActivityInfo.isFixedOrientation(requestedOrientation) ——
表示判断当前的|Activity是否固定了方向,truea为固定了方向。
fullscreen —— 表示Activity是否是透明的或者是否悬浮在Activity上,是透明的或者悬浮在Activity上fullscreen就等于false.
以下三种情况认为不是“fullscreen“:
“windowIsTranslucent”为true;
“windowIsTranslucent”为false,但“windowSwipeToDismiss”为true;
“windowIsFloating“为true;
appInfo.targetSdkVersion > O —— 表示编译版本号大于26
当以上的三个条件同时满足的时候,系统框架就会抛出异常,那意思我们只能让上面的条件不满足就可以了
问题解决方案

1、不固定Activity的方向

2、修改AppTheme的样式为下,windowIsTranslucent设置为false,同时设置windowDisablePreview为true.(这个方法,可以同时满足透明和固定方向)

  <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowIsTranslucent">false</item>
        <item name="android:windowDisablePreview">true</item>
    </style>

本文地址:https://blog.csdn.net/qq_32898021/article/details/110629430

《Only fullscreen opaque activities can request orientation错误记录.doc》

下载本文的Word格式文档,以方便收藏与打印。