Android How to - Change Activity Screen to Vertical








Question

We would like to know how to change Activity Screen to Vertical.

Answer

We can use the constant defined in ActivityInfo to change the orientation to PORTRAIT.


import android.app.Activity;
import android.content.pm.ActivityInfo;

public class Main {
  public static void setScreenVertical(Activity activity) {
    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  }
}