How to Lock Android App's Orientation to Portrait in Phones and Landscape in Tablets?

前端 未结 9 1670
自闭症患者
自闭症患者 2020-12-02 08:44

I am developing an Android app whose orientation I don\'t want changed to landscape mode when the user rotates the device. Also, I want the locked orientation to be portrait

9条回答
  •  [愿得一人]
    2020-12-02 09:03

    You just have to define the property below inside the activity element in your AndroidManifest.xml file. It will restrict your orientation to portrait.

    android:screenOrientation="portrait"

    Example:

            
            
    

    Additionaly, as per Eduard Luca's comment below, you can also use screenOrientation="sensorPortrait" if you want to enable rotation by 180 degrees.

提交回复
热议问题