Question Detail

Screen portrait

1 years ago Views 132 Visit Post Reply

How to change the screen orientation of the entire app.

\r\n


Thread Reply

Anonymous

- 1 years ago

You can specify android:screenOrientation="portrait" for each activity in your manifest.xml file

Raj

- 1 years ago

I want to change it for the entire app in one go not activity by activity.

Hemant Sharma

- 1 years ago

I don't think it can happen.
We need to change it from Manifest file

Hemant Sharma

- 1 years ago

I don't think it can happen.
We need to change it from Manifest file

Ankur Khandelwal

- 1 years ago

Check Out this https://stackoverflow.com/a/44890811/1640009

Anonymous

- 11 months ago

If anyone was wondering , how you could do this for your entire application without having to make all your activities extend a common base class in Kotlin , see the example below :

class InteractiveStoryApplication: Application() {
override fun onCreate() {
    super.onCreate()
    registerActivityLifecycleCallbacks(object: ActivityLifecycleCallbacks {
        override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) {
            activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
        }

        override fun onActivityPaused(activity: Activity?) {
        }

        override fun onActivityResumed(activity: Activity?) {
        }

        override fun onActivityDestroyed(activity: Activity?) {
        }

        override fun onActivitySaveInstanceState(activity: Activity?, outState: Bundle?) {
        }

        override fun onActivityStarted(activity: Activity?) {
        }

        override fun onActivityStopped(activity: Activity?) {
        }
    })
}
}

and then you have to add your common base class in AndroidManifest like so:

<application android:allowBackup="true"
android:name=".InteractiveStoryApplication"