Reputation: 53657
In my application If i want to restrict an activity to work in portrait mode only then i have to write android:screenOrientation="portrait"
in the manifest file against activity tag. If I want to force all activity to work in portrait mode then I have to write the same in all activity. Is there any application-wise setting so that I need not have to write this in all activities. How to make an application to run in portrait mode only
<activity
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation"
android:name=".MyActivity"></activity>
Upvotes: 18
Views: 20299
Reputation: 3224
Recommended way is to use the tag for all activities in manifest. But, if any1 wants laziest approach you can use following code.
In onCreate() of your Application class, include the following code.
registerActivityLifecycleCallbacks(new ActivityLifecycleAdapter() {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
Upvotes: 0
Reputation: 139
HI use this code android:screenOrientation="portrait"
I don't think that there would be another way for this type reuirement
Upvotes: 1
Reputation: 490
<activity android:name=".exampleActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"/>
Upvotes: 1
Reputation: 27
You can support Landscape mode on activity that involve text entry where using a physical keyboard might be required and keeping the rest of your app in portrait mode.
Upvotes: 0
Reputation: 74780
There is no way to set application-wide orientation. But there is one interesting value called behind
:
android:screenOrientation="behind"
But you still need to apply it for each activity. So its better to just stick with portrait
in your case.
Also note that you need to have very good reasons to restrict orientation in your app. In general this is considered a bad practice and may frustrate quite a lot of users.
Upvotes: 2
Reputation: 1213
android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation"
use these line inside your application tag.
it may help you or use this line android:screenOrientation="portrait" with each activity.
Upvotes: -2
Reputation: 4900
I'm afraid that I can't answer your question but I need to write a response anyway.
I'm sure that you're writing the greatest app ever and that there is some awesome reason why it should be locked to portrait mode only. But have you considered phones with slide-out keyboards? If your app involves text entry then anyone with a full qwerty keyboard phone (e.g. Droid/Milestone 1/2, G1, etc) is going to be rotating their phone, sliding out the keyboard and discovering to their horror that the app hasn't rotated with them.
Something to think about. Good luck with your problem and with your app!
Upvotes: 10
Reputation: 22740
Only way is to add android:screenOrientation="portrait"
for each activity.
Upvotes: 45