如何在不使用xml的情况下更改代码中alertdialog中的按钮大小? 我没有使用视图..
谢谢
代码:alertbox3.setNeutralButton("Cancel",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } });
答案 0 :(得分:2)
您可以尝试以下代码:
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);
和 http://developer.android.com/reference/android/widget/Button.html
答案 1 :(得分:1)
您应该使用自定义视图来更改按钮布局。请参阅以下链接,了解如何为alertDialog创建自己的视图。
答案 2 :(得分:0)
试试这个: 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;
答案 3 :(得分:-1)
你为什么这么想?系统将代表您构建标准对话框布局,遵循用户期望和熟悉的约定。一般来说,你不应该试图绕过这个。