Set entire Android Application in Portrait mode only(Portrait Orientation)- Kotlin

On Developing Android application, some application has needed only Portrait mode only (Game: Candy crush) or Portrait Orientation for an entire(full) app or particular on activity. Here we are sharing some common ways to achieve Portrait Mode.

How to Set entire Android Application in Portrait mode only(Portrait Orientation)- Kotlin

How to disable landscape mode for some of the views in my Android app?

There are 2 ways to achieve Activity level Orientation control.

1.  Add android:screenOrientation="portrait" to the activity in the AndroidManifest.xml.

2.  Setting programmatically in Java

Note : In Activity you should call this before setContentView in onCreate() method.

In Kotlin same can be programmatically achieved using this code

And of Landscape in Kotlin

Complete code in Kotlin

How to set an entire android application in portrait mode only?

We are giving example in Kotlin language, Using 2 activity for proper testing, should work on both activities.

for beginners follow this tutorial first Build Your First Android App in Kotlin

Step 1. Create MyApplication class and extend Application class

add following code and methods

Step 2. Don’t forget to add an application in  AndroidManifest.xml.

Complete code AndroidManifest.xml.

Step 3. Create resource layout file activity_second.xml and add following code
Step 4. Create SecondActivity.kt and add this code
Step 5. Add button in activity_main.xml file, complete code
Step 6. Add button_goto.setOnClickListener in MainActivity.kt

for not more about Kotlin Android must read this tutorial: Kotlin Android basic fundamental codes

Step 6. Run the application, in an emulator or On your Android device

Output screenshots Android Application in Portrait mode kotlin example :

Android Application in Portrait mode kotli n
Android Application in Portrait Orientation kotlin

Download source code Android Application in Portrait mode example :

Tag: How to disable landscape mode for the entire application?

or How to force the Android app only “Portrait” orientation mode?

or I want my android application to be only run in portrait mode?

Note : This example (Project) is developed in Android Studio 3.0.1 ,tested on Android 7.1.1 ( Android Nougat), compile SDK version API 26: Android 8.0 (Oreo)

MinSdkVersion=”15″

TargetSdkVersion=”26″

Coding in Kotlin


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.