Can someone tell me how to lock my application to a portrait mode? Is it a simple configuration in the manifest file?
Lock Android phone application to Portrait mode
76.5k views Asked by sexitrainer At
4
There are 4 answers
3
On
None of these answers worked on my system but I did find the following worked perfectly for a simple app that I developed:
Within MainActivity.java add:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
to onCreate ()
This is mine:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
I know that it is not (always) best practice locking orientation, but in special circumstances it is valid and I only want this temporarily while I continue developing.
Yes. Add
android:screenOrientation="portrait"
to the manifest under your main activity.