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

前端 未结 30 1724
难免孤独
难免孤独 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:43

    In android Oreo (API 26) you can not change orientation for Activity that have below line(s) in style

     true
    

    or

     true
    

    You have several way to solving this :

    1) You can simply remove above line(s) (or turn it to false) and your app works fine.

    2) Or you can first remove below line from manifest for that activity

    android:screenOrientation="portrait"
    

    Then you must add this line to your activity (in onCreate())

        //android O fix bug orientation
        if (android.os.Build.VERSION.SDK_INT != Build.VERSION_CODES.O) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    

    3) You can create new styles.xml in values-v26 folder and add this to your style.xml. (Thanks to AbdelHady comment)

     false
     false
    

提交回复
热议问题