1

how can i change the size of button in alertdailog in code without using xml ? I'm not using view ..

Thank you The code : alertbox3.setNeutralButton("Cancel",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } });

Dev
  • 505
  • 2
  • 8
  • 16

4 Answers4

2

you may try this code:

 AlertDialog.Builder adb = new AlertDialog.Builder(this);
 Dialog d = adb.setView(new View(this)).create();
// (That new View is just there to have something inside the dialog that can grow big enough to cover the whole 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);

and http://developer.android.com/reference/android/widget/Button.html

look at this link aslo . Link1 and LInk2

Community
  • 1
  • 1
Horrorgoogle
  • 7,858
  • 11
  • 48
  • 81
1

you should use a customView for your case to change the button layout. see the following link on how to make your own view for alertDialog.

How to implement a custom AlertDialog View

Community
  • 1
  • 1
Yashwanth Kumar
  • 28,931
  • 15
  • 65
  • 69
-1

Try this : https://stackoverflow.com/a/15910202/305135

final AlertDialog alert = builder.create();
alert.setOnShowListener(new DialogInterface.OnShowListener() {
    @Override
    public void onShow(DialogInterface dialog) {
        Button btnPositive = alert.getButton(Dialog.BUTTON_POSITIVE);
        btnPositive.setTextSize(TEXT_SIZE);

        Button btnNegative = alert.getButton(Dialog.BUTTON_NEGATIVE);
        btnNegative.setTextSize(TEXT_SIZE);
    }
});

return alert;
Community
  • 1
  • 1
AVEbrahimi
  • 17,993
  • 23
  • 107
  • 210
-2

Why do you want to? The system will construct a standard dialog layout on your behalf that follows conventions that the user expects and is familiar with. In general you should not go out of your way to circumvent this.

adamp
  • 28,862
  • 9
  • 81
  • 69
  • But if I want to put long statement in button like (Close your App) – Dev Sep 25 '11 at 17:38
  • Dialog button text should be short, use the rest of the dialog to give the options context. Again, this comes down to platform conventions that apps should follow. – adamp Sep 25 '11 at 17:42
  • That's only partly correct. I got a similar problem, because even "short" texts like "Disclaimer" do not fit on SOME devices! That really is a shame for Android device manufacturers to alter font sizes and make your buttons wrap text... – Zordid Nov 14 '11 at 08:05