toggle Full Screen - Android android.app

Android examples for android.app:Screen

Description

toggle Full Screen

Demo Code

import android.app.Activity;
import android.view.Window;
import android.view.WindowManager;

public class Main {

  public static void toggleFullScreen(Activity activity, boolean isFull) {
    hideTitleBar(activity);/*from w  w w.  j  av  a 2s  . c  o m*/
    Window window = activity.getWindow();
    WindowManager.LayoutParams params = window.getAttributes();
    if (isFull) {
      params.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
      window.setAttributes(params);
      window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    } else {
      params.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
      window.setAttributes(params);
      window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }
  }

  public static void hideTitleBar(Activity activity) {
    activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
  }

}

Related Tutorials