Created
September 9, 2016 17:14
-
-
Save DamianSuess/3cf35bcec1c4ecdfd9d0b6d27c4fdd63 to your computer and use it in GitHub Desktop.
Android - Enforce Screen Orientation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace TestApp.Droid | |
{ | |
[Activity(Label = "TestApp", | |
Icon = "@drawable/icon", | |
Theme = "@style/MyTheme", | |
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, | |
NoHistory = true)] | |
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity | |
{ | |
protected override void OnCreate(Bundle bundle) | |
{ | |
// Lock orientation depending on device type | |
switch (Xamarin.Forms.Device.Idiom) | |
{ | |
case TargetIdiom.Phone: | |
RequestedOrientation = ScreenOrientation.Portrait; | |
break; | |
case TargetIdiom.Tablet: | |
RequestedOrientation = ScreenOrientation.Landscape; | |
break; | |
case TargetIdiom.Desktop: | |
default: | |
RequestedOrientation = ScreenOrientation.Unspecified; | |
//RequestedOrientation = ScreenOrientation.Landscape; | |
break; | |
} | |
base.OnCreate(bundle); | |
LoadApplication(new App()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment