java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation

前端 未结 30 1475
难免孤独
难免孤独 2020-12-02 04:43

I am facing the problem while retrieving the contacts from the contact book in Android 8.0 Oreo java.lang.IllegalStateException: Only fullscreen opaque activities can reques

相关标签:
30条回答
  • 2020-12-02 05:45

    I recently faced the issue and here's the solution.

    No need to change the screen orientation parameter which you set at android manifest file.

    Just add two folders in

    res>values
    as  res>values-v26 
    and res>values-v27
    

    Then copy your styles.xml and themes.xml file there.

    and change the following parameters from TRUE to FALSE.

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

    It will work.

    A common bug of Android 8.0

    0 讨论(0)
  • 2020-12-02 05:46

    The only thing that worked for me was changing

    android:screenOrientation="portrait"
    

    to

    android:screenOrientation="unspecified"
    

    in the manifest for all translucent activities.

    That way it is compatible with all API versions since the translucent activity seems to inherit its orientation from the parent activity as of targetApi: 28.

    The style can be left as it is including <item name="android:windowIsTranslucent">true</item>.

    0 讨论(0)
  • 2020-12-02 05:47

    In Android O and later this error happens when you set

     android:screenOrientation="portrait"
    

    in Manifest.

    Remove that line and use

     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    

    in your activity.

    This will fix your issue.

    0 讨论(0)
  • 2020-12-02 05:48

    If you have to use setRequestedOrientation(), there is no way but sacrifice the windowIsTranslucent attribute on Android 8.0

    values\styles.xml for api level 25- (<8.0)

    <style name="Base.Theme.DesignDemo" parent="Base.Theme.AppCompat.Light">
            ...
            <item name="android:windowIsTranslucent">true</item>
            ...
        </style>
    

    values-v26\styles.xml for api level 26 (=8.0)

    <style name="Base.Theme.DesignDemo" parent="Base.Theme.AppCompat.Light">
        ...
        <!-- android 8.0(api26),Only fullscreen opaque activities can request orientation -->
        <item name="android:windowIsTranslucent">false</item>
        ...
    </style>
    

    values-v27\styles.xml for api level 27+ (>8.0)

    <style name="Base.Theme.DesignDemo" parent="Base.Theme.AppCompat.Light">
        ...
        <item name="android:windowIsTranslucent">true</item>
        ...
    </style>
    
    0 讨论(0)
  • 2020-12-02 05:49

    I had the same problem, and my solution was to eliminate the line

    android:screenOrientation="portrait"
    

    and then add this in the activity:

    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    
    0 讨论(0)
  • 2020-12-02 05:50

    only 8.0.0 throw the exception, above 8.0 has remove the exception

    0 讨论(0)
提交回复
热议问题