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.
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.
You will get strange errors if you use anything .NoTitleBar
I would suggest using a theme like:Theme = "@android:style/Theme.Holo.Light"
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)]
Thanks, this solved the android side of things, but what about iOS?
Just toggle on/off the orientations you want in Project Options
@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)]
ScreenOrientation = Android.Content.PM.ScreenOrientation.Landscape)]
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.
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)]
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.
Xamarin Inc., as a wholly-owned Microsoft subsidiary acting as a separate legal entity, adheres to the Microsoft Privacy Statement: Privacy & cookies