Forum Xamarin.Forms

Turning off screen rotation XAML forms

How do I turn off screen rotation for my app in XMAL or the attached CS. I want my page to only load vertically and not change to horizontal view.


  • xceedxceed GBMember ✭✭

    Activity(Label = "MyApp1", MainLauncher = true, Icon = "@drawable/icon", ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait, Theme = "@android:style/Theme.NoTitleBar.Fullscreen")]

    Remove the Theme part if you don't want fullscreen.


  • RyanHatfieldOldRyanHatfieldOld USMember, Insider ✭✭✭

    Whoa buddy!

    You will get strange errors if you use anything .NoTitleBar

    I would suggest using a theme like:
    Theme = "@android:style/Theme.Holo.Light"

    Here's what's generated in the newest android project templates:

    [Activity(Label = "ProjName.Mobile", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, Theme = "@style/android:Theme.Holo")]

    but my current project uses

    [Activity(Label = "ProjName.Mobile", MainLauncher = true, ScreenOrientation = ScreenOrientation.Portrait, Theme = "@style/android:Theme.Holo.Light", WindowSoftInputMode = SoftInput.AdjustResize)]


  • Rick.0957Rick.0957 USMember

    Thanks, this solved the android side of things, but what about iOS?

  • CraigDunnCraigDunn USXamarin Team Xamurai

    Just toggle on/off the orientations you want in Project Options


  • xceedxceed GBMember ✭✭

    @RyanHatfield what kind of errors for using anything .NoTitleBar?

    I'm not actually using it now anyway.

    I still require Window.AddFlags(WindowManagerFlags.Fullscreen); however inside my MainActivity's OnCreate.

    The only thing I've added to the Activity modifier is ScreenOrientation = Android.Content.PM.ScreenOrientation.Landscape)]


  • RyanHatfieldOldRyanHatfieldOld USMember, Insider ✭✭✭

    In android if I used NoTitleBar with a NavigationPage it would throw an error, NullReference, when looking for the Title Bar ... maybe they fixed it.

  • Thx :)

  • BlueRajaBlueRaja USMember ✭✭

    Not sure what all this talk about the theme and full-screen is about, but it seems the actual solution is

    [Activity( ..., ScreenOrientation = ScreenOrientation.Portrait)]

  • SteveShaw.5557SteveShaw.5557 USMember ✭✭✭
    edited October 2018

    NOTE: The solutions in this thread are appropriate if you want all your pages to have a certain orientation.

    If you want one or several pages to have a particular orientation, that are different than what you've set above for your application default, look for solutions elsewhere.

Sign In or Register to comment.