Dilshi
Dilshi

Reputation: 553

Cannot change the android dialog size

            final CharSequence[] options={"Indoor Pharmacy","Outdoor   Pharmacy","Laborataory"};

              AlertDialog.Builder builder3=new AlertDialog.Builder(MainActivity.this);
               builder3.create().getWindow().setLayout(1200, 1530);
                builder3.setTitle("Pick your choice").setItems(options, new DialogInterface.OnClickListener() {

                @Override

                public void onClick(DialogInterface dialog, int which) {

              // TODO Auto-generated method stub

              Toast.makeText(getApplicationContext(), "U clicked "+items[which], Toast.LENGTH_LONG).show();

              }

              });

                builder3.show()

i tried above code to display dialog box with 3 options.it works fine but i need to change the size of the dialog box.Can you help me with this.

Upvotes: 0

Views: 8861

Answers (6)

CodyBugstein
CodyBugstein

Reputation: 23322

Do you still have a title bar? This could be forcing your Dialog box into a specific size.

Try this code in your DialogFragment subclass (or Dialog subclass, without getDialog()):

    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

Upvotes: 0

Jayanth Ramanatha
Jayanth Ramanatha

Reputation: 21

Use this line of code if you want it with respect to your screen size

int width = getWindowManager().getDefaultDisplay().getWidth() - x;    
int height = getWindowManager().getDefaultDisplay().getHeight() - y; 
//where x and y are margin as required for ur dialog


AlertDialog.Builder builder3=new AlertDialog.Builder(MainActivity.this);
builder3.create().getWindow().setLayout(width, height);
builder3.setTitle("Pick your choice").setItems(options, new DialogInterface.OnClickListener() {
//rest of ur code
}

Upvotes: 2

Sanket Shah
Sanket Shah

Reputation: 4382

just add following code

Window window = Your_Dialog.getWindow();
window.setLayout(1300,900);

Upvotes: 2

Thanh Duy Ngo
Thanh Duy Ngo

Reputation: 1611

I think you can try to create a dialog layout and call it in your code resource.

Upvotes: 0

Tarsem Singh
Tarsem Singh

Reputation: 14199

try

AlertDialog.Builder builder3=new AlertDialog.Builder(MainActivity.this);
Dialog d = builder3.setView(new View(this)).create();
d.getWindow().setLayout(600, 400);
d.show();

Upvotes: 0

Armaan Stranger
Armaan Stranger

Reputation: 3130

Try this line code:

builder3.create().getWindow().setLayout(300, 200);

Hope it Helps!!

Upvotes: 3

Related Questions