Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android. Lock orientation of screen for all Activities [duplicate]

Possible Duplicate:
How can I set Orientation Fixed for all activities

I would like to lock my screen orientation for my app. I mean that all Activities must have the same landscape orientation. I don't want to add android:screenOrientation="portrait" in the manifest for all activities. Is there any other way? thanks Regards

like image 725
Hayk Nahapetyan Avatar asked Oct 12 '12 13:10

Hayk Nahapetyan


People also ask

How do I lock orientation in Android programmatically?

setRequestedOrientation(ActivityInfo. SCREEN_ORIENTATION_LANDSCAPE); Called on an activity, will lock it to landscape.


1 Answers

You have two options for achieving the result.

  • You can specify per activity base orientation requirement in manifest file. You can select here what orientation you want to support for which activity.

e.g.

<activity
    android:name=".Some_Act"
    android:label="@string/app_name"
    android:screenOrientation="portrait" >
</activity>
  • You can create a base activity and specify the orientation in that activity. Later you can inherit that activity in other activities of your application. You can choose suitable base class to get the desired behavior.
like image 118
Murtuza Kabul Avatar answered Nov 03 '22 10:11

Murtuza Kabul