Size of button in alertdialog

2019-07-31 17:45发布

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) { } });

4条回答
男人必须洒脱
2楼-- · 2019-07-31 18:19

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.

查看更多
放我归山
3楼-- · 2019-07-31 18:21

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

查看更多
Melony?
4楼-- · 2019-07-31 18:29

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

查看更多
虎瘦雄心在
5楼-- · 2019-07-31 18:29

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;
查看更多
登录 后发表回答