Check out this code and tell me what you really wanted to achieve?
AlertDialog.Builder builder = new AlertDialog.Builder(this); // Creates textview TextView text = new TextView(this); text.setText("Hello This text"); text.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); text.setTextSize(20); text.setGravity(Gravity.CENTER); //Creates a linearlayout layout and sets it with initial params LinearLayout ll = new LinearLayout(this); ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); ll.setGravity(Gravity.CENTER); ll.addView(text); //adds textview to llayout builder.setMessage("Title").setPositiveButton( "Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); Dialog d = builder.setView(ll).create(); //Fills up the entire Screen WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(d.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; d.show(); d.getWindow().setAttributes(lp);
source share