Lock screen orientation when targeting Android API 27 with a non-opaque activity

前端 未结 9 734
囚心锁ツ
囚心锁ツ 2020-12-13 09:30

I have an activity that has android:windowIsTranslucent set to true and android:windowBackground set to a translucent background. I ju

相关标签:
9条回答
  • 2020-12-13 09:51

    1) Remove this

    android:screenOrientation="portrait" 
    

    from minifiest.xml

    2) on Activity add these two lines

     protected void onCreate(Bundle savedInstanceState) {
         setOrientation(this)
         super.onCreate(savedInstanceState);
         // other other all code here
    
     }
    

    3) Just copy-paste the code in your Activity

     public static void setOrientation(Activity context) {
              if (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.O)
                  context.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
              else
                  context.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    
    0 讨论(0)
  • 2020-12-13 09:57

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

    No need to change the screen orientation parameter which you set at the 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-13 10:01

    I solved this issues by changing this line in NoActionBar styles

    In target version 27 only i got this issue and i solved by using below line

    <item name="android:windowIsTranslucent">false</item>
    
    0 讨论(0)
提交回复
热议问题