我们可以在Android警告对话框垂直按钮? [英] Can we have vertical buttons in an Android alert dialog?

查看:405
本文介绍了我们可以在Android警告对话框垂直按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在默认情况下,我们得到了在一个警告对话框水平排列的两个或三个按钮。是否有可能让他们警告对话框内的垂直对齐?

By default, we get two or three buttons that are horizontally aligned in an alert dialog. Is it possible to have them vertically aligned within the alert dialog?

推荐答案

当然,你可以使用Dialog.setContentView()来设置一个对话框的内容是任意的布局。

Sure, you can use Dialog.setContentView() to set the content of a dialog to be an arbitrary layout.

    Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.yourLayoutId);
    dialog.show();

请自己一个垂直的LinearLayout有你想要它,并调用的setContentView您的对话框上的按钮布局文件,传递你的布局文件的名称。

Make yourself a layout file with a Vertical LinearLayout that has the buttons you want in it and call setContentView on your dialog, passing the name of your layout file.

如果您在AlertDialog压力固定,你可以做类似与builder.setView东西()

If you are deadset on AlertDialog you can do something similar with builder.setView()

    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.yourLayoutId, (ViewGroup) findViewById(R.id.yourLayoutRoot));
    AlertDialog.Builder builder = new AlertDialog.Builder(this)
    .setView(layout);
    AlertDialog alertDialog = builder.create();
    alertDialog.show();

这篇关于我们可以在Android警告对话框垂直按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆