It is said here and here that using ScreenOrientation = ScreenOrientation.Portrait
can force-lock the app's orientation:
[Activity(
Label = "SomeApplication",
MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
ScreenOrientation = ScreenOrientation.Portrait
)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
}
Also tried editing AndroidManifest.xml
like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.package.SomeApplication">
<uses-sdk android:minSdkVersion="15" />
<application android:label="SomeApplication.Android">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
</activity>
</application>
</manifest>
and this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.package.SomeApplication">
<uses-sdk android:minSdkVersion="15" />
<application android:label="SomeApplication.Android">
</application>
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
</activity>
</manifest>
But every time I run the app, I can still rotate it in landscape mode. My phone also has Auto-Rotate
enabled, but I don't think that is an issue.
What else did I miss?