get Immersive Activity - Android Activity

Android examples for Activity:Activity Action

Description

get Immersive Activity

Demo Code


import android.app.ActionBar;
import android.app.Activity;
import android.graphics.Point;
import android.os.Build;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;

public class Main {
  public static void getImmersive(Activity self, boolean actionbr) {
    if (Build.VERSION.SDK_INT < 16) {
      self.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
          WindowManager.LayoutParams.FLAG_FULLSCREEN);
    } else {//ww w  .j  av  a 2  s.c o  m
      View decorView = self.getWindow().getDecorView();
      // Hide the status bar.
      int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
      decorView.setSystemUiVisibility(uiOptions);
      ActionBar actionBar = self.getActionBar();
      if (actionBar != null)
        actionBar.hide();

      Display display = self.getWindowManager().getDefaultDisplay();
      Point size = new Point();
      display.getSize(size);
      if (!actionbr) {
        if (Build.VERSION.SDK_INT >= 19) {
          decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
              | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
              | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN
              | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

        }
      }
    }
  }
}

Related Tutorials