create Dialog Full Screen - Android android.app

Android examples for android.app:Screen

Description

create Dialog Full Screen

Demo Code

import android.app.AlertDialog;
import android.content.Context;
import android.view.Window;
import android.view.WindowManager;

public class Main {

  public static AlertDialog createDialogFullScreen(Context context, int layout, boolean showSoftInput) {
    AlertDialog dialog = new AlertDialog.Builder(context).create();
    dialog.show();//from  w ww. jav a 2 s.  co m
    dialog.setContentView(layout);
    Window window = dialog.getWindow();
    if (showSoftInput) {
      window
          .clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
      window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    }
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.MATCH_PARENT;
    window.setAttributes(lp);

    return dialog;
  }

}

Related Tutorials