Disable landscape mode for the whole application

Is there a way to set landscape mode for the whole application, and not by adding android:screenOrientation="portrait" to each activity in AndroidManifest?

+6
source share
3 answers

Here is the only thing I can think of. Write a class that extends Activity and puts the following into this class:

 setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

Then, instead of continuing the Activity in other classes, add a new class.

+10
source

One programmatic way to do this that I can think of is to create a superclass that expands activity and extends all your classes from there.

Install the class below in a super class in a protected method and call super.xxx () to initiate this:

 setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

If you have a specific activity differently, you can simply redefine it.

[I have not tried this yet, but according to OOP knowledge it works]

+7
source

You can try placing this attribute in the node of your manifest. However, I do not know if this is supported. And if not, then I'm afraid to put it in each of yours will be the next easiest way.

You may be able to achieve this by creating a CustomActivity that expands the activity and sets the window flags as Portrait in onCreate. Then, with all your other actions, you can expand your CustomActivity instead of just activity.

0
source

Source: https://habr.com/ru/post/895627/


All Articles