In AndroidManifest: Expecting android:screenOrientation=“unspecified”

前端 未结 11 863
隐瞒了意图╮
隐瞒了意图╮ 2021-02-02 04:59

Android Studio 3.6.

I want my app to be always in portrait mode. So in my AndroidMainfest.xml:



        
相关标签:
11条回答
  • 2021-02-02 05:38

    I have faced this issue, In my requirement, some of the activity will support both orientations and remains will keep in portrait, In this case, I resolved by the following steps:

    Case-1:- To lock Orientation

    Step-1: Please Add following line Application tag in AndroidManifest.xml

    tools:ignore="LockedOrientationActivity"

    <application
    android:name=".activity.MyApplication"
    tools:ignore="LockedOrientationActivity">
    

    Step-2: If you want to lock screen orientation either in portrait or landscape add the following line in the activity tag

    android:screenOrientation="portrait" or "landscape"

    Case-2:- Suppose if u want to allow orientation in particular activity and have a specific design for landscape

    Step-1: Remove Orientation value in configchanges and remove screen orientation if it exists from activity tag, and my personal suggestion use (LifecycleObserver) in Activity for without losing values while changing orientation.

    android:configChanges="orientation"
    android:screenOrientation="portrait" or "landscape"

    This is the way I resolve this issue, hope it helps, Thanks & Happy Coding.

    0 讨论(0)
  • 2021-02-02 05:39

    In Android studio 3.6.0 i guess they want the user to handle the orientation and encourage developer to use ViewModel stuff. Let me explain screenOrientation in detail

    android:screenOrientation="portrait"

    will give you error you have to either specify

    android:screenOrientation="fullSensor" or android:screenOrientation="unspecified"

    fullSensor Means either you have ON the "Rotate off" or not it will change the orientation based on you move the phone

    unspecified Means if you have ON the Rotate off then it will stay only in that orientation and if not then it will change the orientation based on you move the phone.

    0 讨论(0)
  • 2021-02-02 05:40

    Add following line after android:screenOrientation="portrait"

    tools:ignore="LockedOrientationActivity"
    

    Then click Alt+Enter

    enter image description here

    0 讨论(0)
  • 2021-02-02 05:45

    Try putting the following in the activity tag

    android:configChanges="orientation"
    android:screenOrientation="portrait" 
    
    0 讨论(0)
  • 2021-02-02 05:46

    In your manifest tag (just under xmlns:android="http://schemas.android.com/apk/res/android"), put

    xmlns:tools="http://schemas.android.com/tools"
    

    Then inside the application tag, put

    tools:ignore="LockedOrientationActivity"
    
    0 讨论(0)
  • 2021-02-02 05:47
    tools:ignore="GoogleAppIndexingWarning,LockedOrientationActivity"
    
    0 讨论(0)
提交回复
热议问题