Reputation: 183
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?
Upvotes: 13
Views: 9914
Reputation: 21
Prevent your kotlin activity from rotating to write this is in your AndroidManifest.xml file
< activity android:name=".activity_name"
android:screenOrientation="nosensor" >< /activity>
Upvotes: 2
Reputation: 121
In MainActivity you could use ...
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
**requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;**
Upvotes: 2
Reputation: 159
In Kotlin you can write same code which is you written in java because manifest file is written in xml file so you have to put just these line in activity Tag.
android:screenOrientation="portrait"
Upvotes: 3
Reputation: 325
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?
Upvotes: 9
Reputation: 1658
It does not matter whether you use java or kotlin. The android sdk is a different thing and you should not confuse that with programming language. Kotlin code looks different from java because of syntactical differences in language. Under the hood both are the same bytecode.
Your android manifest is written in xml, its just like a configuration file and is not affected by your choice of programming language for the code. So, their is no need to change anything in the manifest file. You, can directly use :
android:screenOrientation="portrait"
Upvotes: 6