You are currently viewing How to Disable landscape mode in Xamarin.Android?
Xamarin

How to Disable landscape mode in Xamarin.Android?

How to Disable landscape mode in Xamarin.Android?

If you want to Disable Landscape mode or Portrait mode in Xamarin.Android you need to set activity screen orientation attribute for that Activity.

Here is the example to Disable landscape mode in Xamarin.Android

 [Activity(Label = "@string/ApplicationName",ScreenOrientation =Android.Content.PM.ScreenOrientation.Portrait)]
    public class MainActivity : AppCompatActivity
{
    //.....
}

In the above example, we set ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait means this activity open with Portrait mode only. Activity remains in the Portrait mode while rotating the mobile.

Same as above you can Disable portrait mode in Xamarin.Android

 [Activity(Label = "@string/ApplicationName",ScreenOrientation =Android.Content.PM.ScreenOrientation.Landscape)]
    public class MainActivity : AppCompatActivity
{
    //.....
}

If your application related to so Gaming functionality then you might require Landscape mode only so you need to disable portrait mode as above example.

You may also like my other Android related posts: Android Posts