Search code examples
androidandroid-fragmentsandroid-activityscreen-orientationportrait

How to apply screen orientation to portrait too all the layouts at once android studio


Hello im making an app where i want is that all the layouts should be lock in potrait inshrot i want my app in potrait even user try to make it in landscape

i have some idea but dont if it works or not

in my app i have only one main activity and all rest of are fragments so my idea is if i give reqiredActivity to potrait to main activity will it work

right now im giving each fragment requiredAcitivity to potrait but when i have many fragments in the future it can be a hastle for me

 requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Solution

  • You can set it in your activity Manifest XML. screenOrientation.

    <activity
                android:name=".Android_mobile_infoActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
      </activity>