Skip to content

Instantly share code, notes, and snippets.

@DamianSuess
Created September 9, 2016 17:14
Show Gist options
  • Save DamianSuess/3cf35bcec1c4ecdfd9d0b6d27c4fdd63 to your computer and use it in GitHub Desktop.
Save DamianSuess/3cf35bcec1c4ecdfd9d0b6d27c4fdd63 to your computer and use it in GitHub Desktop.
Android - Enforce Screen Orientation
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