Android How to - Change Activity Screen to Horizontal








Question

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

Answer

We can use the Constants defined in ActivityInfo to change the orientation to landscape.


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

public class Main {
  public static void setScreenHorizontal(Activity activity) {
    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
  }
}