【问题标题】:android error: IllegalStateException: Only fullscreen opaque activities can request orientationandroid错误:IllegalStateException:只有全屏不透明活动可以请求方向
【发布时间】:2021-05-18 06:47:20
【问题描述】:

当设备处于横向模式时,我有一个从浏览器打开的活动让我出现以下错误

java.lang.IllegalStateException:只有全屏不透明活动才能请求方向

清单

<activity android:name=".Activity.MyActivity"
        android:configChanges="orientation"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.Theme_Slide"
        >
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="xxx"
                android:scheme="xxx" />
            <data
                android:host="xxx"
                android:scheme="xxx" />
        </intent-filter>
    </activity>

style.xml

<style name="AppTheme.Theme_Slide" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowCloseOnTouchOutside">false</item>
</style>

【问题讨论】:

    标签: android


    【解决方案1】:

    更新查找解决方案

    在 android Oreo (API 26) 中,您不能更改具有以下样式的 Activity 的方向

     <item name="android:windowIsTranslucent">true</item>
    

    你有两种方法可以解决这个问题:

    1. 您可以简单地删除上面的行(或将其设置为 false),您的应用程序就可以正常工作了。

    2. 或者您可以先从该活动的清单中删除以下行

      android:screenOrientation="portrait"

    那么你必须将这一行添加到java文件中

    //android O修复bug方向

    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    

    【讨论】:

      猜你喜欢
      • 2018-07-07
      • 1970-01-01
      • 1970-01-01
      • 2018-04-10
      • 2018-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多