Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force "portrait" orientation mode

I'm trying to force the "portrait" mode for my application because my application is absolutely not designed for the "landscape" mode.

After reading some forums, I added these lines in my manifest file:

<application    android:debuggable="true"   android:icon="@drawable/icon"    android:label="@string/app_name"   android:screenOrientation="portrait"> 

But it doesn't work on my device (HTC Desire). It switches from "portrait" lo "landscape", ignoring the lines from the manifest file.

After more forums reading, I tried to add this in my manifest file:

<application    android:debuggable="true"   android:icon="@drawable/icon"    android:label="@string/app_name"   android:configChanges="orientation"          android:screenOrientation="portrait"> 

and this function in my activity class:

public void onConfigurationChanged(Configuration newConfig) {     super.onConfigurationChanged(newConfig);     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } 

But again, no luck.

like image 473
thomaus Avatar asked Feb 03 '11 11:02

thomaus


People also ask

How do I force an app to stay in portrait mode?

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."

How do I force portrait in IOS?

Swipe down from the top-right corner of your screen to open Control Center. Tap the Portrait Orientation Lock button to make sure that it's off.

How do I force landscape in IOS?

On an iPhone without a Home button, swipe down from the top-right corner of the screen instead. Here, tap on the rotation lock icon (which looks like a lock with a circular arrow) to turn it on or off.


1 Answers

Don't apply the orientation to the application element, instead you should apply the attribute to the activity element, and you must also set configChanges as noted below.

Example:

<activity    android:screenOrientation="portrait"    android:configChanges="orientation|keyboardHidden"> </activity> 

This is applied in the manifest file AndroidManifest.xml.

like image 187
C0deAttack Avatar answered Sep 18 '22 19:09

C0deAttack