I would like to have my app only in landscape mode. For that I use the suggested code in the Android manifest that is recommended here Force "portrait" orientation mode
However, on the Android emulator the layout is always in portrait mode. Even if I rotate the Emulator, the layout orientation does not change. Any idea why this problem occurs?
Here you can see the Android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nikhiljain.canvasdrawingsample">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.CanvasDrawingSample">
<activity android:name=".MainActivity">
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
and here is the main file:
package com.nikhiljain.canvasdrawingsample
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
CodePudding user response:
you are closing <activity
tag too soon, rest of attributes (besides name
) are outside declaration and "doesn't count"
<activity android:name=".MainActivity"> <----- !!!!
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden">
should be
<activity android:name=".MainActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden">