I've made a Kotlin app and I don't want the app's screen to rotate. I know that with Java, I can just put
android:screenOrientation="portrait"
in the AndroidMainfest, but how about Kotlin? How can I do it?
Tap the Settings icon to open the Settings app. Scroll down and tap Accessibility. Scroll down to Interaction controls and tap Auto-rotate screen to turn it off.
Add android:screenOrientation="portrait" to the activity you want to disable landscape mode in.
If you've enabled auto-rotate, your Android phone's screen is supposed to rotate when turn your phone 90 degrees or more. Sometimes, though, you might notice that this doesn't happen. It's possible a third-party app, a system glitch, or a faulty sensor is causing your phone not to recognize the movement.
In MainActivity you could use ...
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
**requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;**
AndroidManifest is a .xml file. You don't write Kotlin code in there. So you can still use:
<activity android:name=" example.com.YourActivity"
android:screenOrientation="portrait"> //or "landscape"
</activity>
This answer could be helpful for you too How to set entire application in portrait mode only?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With