Size of button in alertdialog

馋奶兔 提交于 2019-12-13 17:33:13

问题


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


回答1:


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




回答2:


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




回答3:


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;



回答4:


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.



来源:https://stackoverflow.com/questions/7547233/size-of-button-in-alertdialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!