I want to disable landscape mode for my entire application. I want to be able to do so without setting screenOrientation
to portrait for each activity in my manifest. Is it possible to do it with one attribute?
Asked
Active
Viewed 7,446 times
1

the_prole
- 8,275
- 16
- 78
- 163
-
http://stackoverflow.com/questions/6745797/how-to-set-entire-application-in-portrait-mode-only[enter link description here](http://stackoverflow.com/questions/6745797/how-to-set-entire-application-in-portrait-mode-only) Have a look, your problem will be solved – Gajendra Singh Rathore May 02 '17 at 00:52
-
Possible duplicate of [How to set entire application in portrait mode only?](http://stackoverflow.com/questions/6745797/how-to-set-entire-application-in-portrait-mode-only) – Mukesh M May 02 '17 at 03:26
3 Answers
6
Simply, in the manifest file add android:screenOrientation to all the defined activities.
<activity android:name=".YourActivity"
android:screenOrientation="portrait"/>
It will make all your activities to stick only to portrait mode only. Just add the screenOrientation to all the activities.

Nikhil
- 1,212
- 13
- 30
1
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
in onCreate() method. just create a BaseActivity and each your activity extends with this BaseActivity.
public SampleActivity extends BaseActivity{
}
public class BaseActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
Edit
In Manifest
<activity
android:name=".ui.hello.Activity"
android:label="@string/apa_nama"
android:screenOrientation="portrait">

ZeroOne
- 8,996
- 4
- 27
- 45
1
In the manifest, set this for all your activities:
<activity android:name=".YourActivity"
android:screenOrientation="portrait"/>
portrait oriented restrict your activity to change orientation to landscape. You have to put this line for each activity in Manifest file.

Jitesh Prajapati
- 2,533
- 4
- 29
- 51