3

How do I programmatically disable screen rotations for an entire Android application?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Krish
  • 3,860
  • 1
  • 19
  • 32
  • are you ok to do it in every activity? May be this link helps you http://stackoverflow.com/questions/1512045/how-to-disable-orientation-change-in-android – kosa Feb 14 '12 at 04:56
  • check the following link. http://stackoverflow.com/questions/2366706/how-to-lock-orientation-during-runtime – Raj Feb 14 '12 at 04:57
  • No, i have more activity in my application – Krish Feb 14 '12 at 05:01

4 Answers4

6

As in keep it in portrait or Landscape no matter which way device is tilted? You need to add this to your manifest inside the activity that you want to limit

 android:screenOrientation="portrait" //Or landscape for horizontal.

If you want it different between activities just make your manifest look like this.

        <activity android:name=".Activity1" 
        android:screenOrientation="landscape">       
        </activity>

        <activity android:name=".Activity2" 
        android:screenOrientation="portrait">
        </activity>

        <activity android:name=".Activity3" 
        android:screenOrientation="landscape">
        </activity>
sealz
  • 5,348
  • 5
  • 40
  • 70
3

Fix the orientation in android manifest for every activity

        <activity  android:name=".SomeNewDesignActivity"  
           android:screenOrientation="portrait"  ></activity>
Tofeeq Ahmad
  • 11,935
  • 4
  • 61
  • 87
2

Too late to the party!

Anyway if you want to disable rotation without forcing the user to choose landscape or portrait you can use in each activity in the manifest

android:screenOrientation="locked"

So your manifest should look like this

    <activity android:name=".Activity1" 
      android:screenOrientation="locked">       
    </activity>

    <activity android:name=".Activity2" 
      android:screenOrientation="locked">
    </activity>

    <activity android:name=".Activity3" 
      android:screenOrientation="locked">
    </activity>

So the app will keep the current orientation the user decided to use.

The same behaviour can be obtained programamtically:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
Fabio
  • 782
  • 4
  • 8
  • 25
0

Best way to do screen orientation to potrait/landscap for entire app -

Add following lines in your app theme - 

for making all activity portrait - 



<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
 
    <item name="android:screenOrientation">portrait</item>
</style>

for making all activity landscape -

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
 
    <item name="android:screenOrientation">landscape</item>
</style>
Saiful Islam Sajib
  • 2,243
  • 1
  • 12
  • 17