Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable screen rotating on Android [duplicate]

When I press a button, I would like to disable screen rotation on all my activities. How can I do that?

BTW, the phone can be located in landscape or portrait position when the user click the button.

like image 581
davs Avatar asked Nov 27 '25 16:11

davs


2 Answers

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

like image 169
androidworkz Avatar answered Nov 29 '25 06:11

androidworkz


You can change your AndroidManifest.xml to

<activity android:name="MainActivity" android:configChanges="orientation">

Which informs the OS that you will handle these config changes (by doing nothing.)

See How do I disable orientation change on Android?

like image 28
mdma Avatar answered Nov 29 '25 04:11

mdma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!