Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an application ignore screen orientation change?

Tags:

android

Is there a way to make an application completely ignore a screen orientation change?

like image 304
Lyubomyr Dutko Avatar asked Sep 11 '09 12:09

Lyubomyr Dutko


People also ask

How do I lock my app orientation?

On the main screen of Rotation Manager, select an orientation by tapping on either the vertical or horizontal icons next to a specific app to lock it into either landscape or portrait mode. Highlighting both icons will allow that particular app to auto-rotate.

Is there a way to force apps to Rotate?

Android Settings Start by going to Settings => Display and locate the “Device rotation” setting. On my personal cell phone, tapping this will reveal two options: “Rotate the contents of the screen,” and “Stay in portrait view.”

What should you use to block the app during phone changes its orientation?

In Android Studio 1 one simple way is to add android:screenOrientation="nosensor" . This effectively locks the screen orientation.


1 Answers

It is possible, quite easily, to override the default behavior and forbid a screen orientation change when the keyboard is open/closed.

Modifying the manifest

Open the manifest, switch to the Application tab and select the desired Activity you wish to override for the orientation change behavior.

  1. Within Attributes you need to change two fields: Screen orientation: select either portrait or landscape - whichever is desired. This will be the default layout.

  2. Select events for Config changes you wish to override: In this case these are keyboardHidden and orientation.

Modifying the Activity implementation

Now you need to override a single function within desired Activity.

Just add the function below to your Activity's class.

@Override public void onConfigurationChanged(Configuration newConfig) {     super.onConfigurationChanged(newConfig); } 

This is the default implementation if using the Source->Override/Implement Methods menu option.

That's it! Now your orientation will always be kept.

Remember that this setting is per Activity - so you need to repeat this step for each Activity you wish to forbid the orientation change!

(Based on SDK 1.1)

like image 69
Marcin Gil Avatar answered Sep 21 '22 01:09

Marcin Gil