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

前端 未结 9 759
囚心锁ツ
囚心锁ツ 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

    The solution worked for me is deleting

    android:screenOrientation="portrait" 
    

    from all the full screen transparent activities which means their theme contains

    true
    

    Also to make sure that orientation works correct for below Oreo I added this to the onCreate() of the activities.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // This activity is a fullscreen transparent activity, so after Oreo Android doesn't allow fullscreen
        // transparent activities to specify android:screenOrientation="portrait" in the manifest. It will pick up
        // from the background activity. But for below Oreo we should make sure that requested orientation is portrait.
        if (VERSION.SDK_INT < VERSION_CODES.O) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    }
    

提交回复
热议问题