androidandroid-manifestandroid-orientation

How can I disable landscape mode in Android?


How can I disable landscape mode for some of the views in my Android app?


Solution

  • Add android:screenOrientation="portrait" to the activity in the AndroidManifest.xml. For example:

    <activity android:name=".SomeActivity"
              android:label="@string/app_name"
              android:screenOrientation="portrait" />
    

    Since this has become a super-popular answer, I feel very guilty as forcing portrait is rarely the right solution to the problems it's frequently applied to.
    The major caveats with forced portrait:

    So most apps should just let the phone sensors, software, and physical configuration make their own decision about how the user wants to interact with your app. A few cases you may still want to think about, though, if you're not happy with the default behavior of sensor orientation in your use case: