警报对话框中按钮的大小

发布于 2024-12-06 07:21:24 字数 222 浏览 0 评论 0原文

如何在不使用 xml 的情况下更改代码中 Alertdailog 中按钮的大小? 我没有使用视图..

谢谢 代码: alertbox3.setNeutralButton("取消",new DialogInterface.OnClickListener() { public void onClick(DialogInterfacedialog, int which) { } });

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寂寞陪衬 2024-12-13 07:21:24

你可以尝试这个代码:

 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

看看这个链接。 Link1LInk2

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

征棹 2024-12-13 07:21:24

您应该为您的案例使用 customView 来更改按钮布局。请参阅以下链接,了解如何创建您自己的警报对话框视图。

如何实现自定义 AlertDialog 视图

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

×眷恋的温暖 2024-12-13 07:21:24

试试这个:
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;

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;
最舍不得你 2024-12-13 07:21:24

你为什么想要?系统将代表您构建一个标准对话框布局,该布局遵循用户期望和熟悉的约定。一般来说,您不应该竭尽全力来规避这一点。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文