Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Orientation change in Xamarin Android Application

Is it possible to prevent the orientation of an Android application from changing ? I have an application that previews the phone camera and I would like the orientation not to change.

I have tried adding this to the manifest but it did not make a difference

<application android:label="TextureViewCameraStream" android:hardwareAccelerated="true">     </application>     <activity        android:screenOrientation="portrait"        android:configChanges="orientation|keyboardHidden">     </activity> 

I am using Xamarin for Android and C#

Thank you

like image 292
G-Man Avatar asked Mar 18 '14 04:03

G-Man


People also ask

What is orientation in xamarin forms?

Xamarin. Android supports several options for specifying orientation: Landscape – forces the application orientation to be landscape, regardless of sensor data. Portrait – forces the application orientation to be portrait, regardless of sensor data.

How do you handle rotation?

If you want to manually handle orientation changes in your app you must declare the "orientation" , "screenSize" , and "screenLayout" values in the android:configChanges attributes. You can declare multiple configuration values in the attribute by separating them with a pipe | character.


2 Answers

Set it in the Activity flag like this:

[Activity (Label = "YourActivityname", MainLauncher = true, ScreenOrientation = ScreenOrientation.Portrait)]  
like image 129
Sajeetharan Avatar answered Sep 23 '22 13:09

Sajeetharan


If you have an Activity, and you want to keep your activity in the same orientation when it is opened, then use this label:

[Activity(Label = "MyApp", ScreenOrientation = Android.Content.PM.ScreenOrientation.Locked)] 
like image 37
Led Machine Avatar answered Sep 23 '22 13:09

Led Machine