AlertDialog中应使用哪些LayoutParams? [英] What LayoutParams should be used in an AlertDialog?

查看:167
本文介绍了AlertDialog中应使用哪些LayoutParams?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 EditText 对象:

    EditText textbox = new EditText (this);
    textbox.setHint (something);

我想将此视图添加到 AlertDialog

I want to add this view to an AlertDialog using the builder.

    AlertDialog.Builder builder = new AlertDialog.Builder (this);
    builder.setTitle (R.string.enter_password_name)
            .setPositiveButton (R.string.save_text, new DialogInterface.OnClickListener () {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            })
            .setNegativeButton (R.string.cancel_text, new DialogInterface.OnClickListener () {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            });

我知道有一种方法 setView(int),但我使用的是API 15,因此只能使用 setView(View),这也是我通过代码创建视图的原因。

I know that there is a method setView(int) but I am using API 15 so I can only use setView(View), which is also a reason why I am creating the view by code.

到目前为止,还不错,但是我现在需要设置视图的 LayoutParams 。我应该选择什么 LayoutParams ?我知道在 RelativeLayout 中,您可以使用 RelativeLayout.LayoutParams LinearLayout 使用 LinearLayout.LayoutParams 。但是我应该在对话框中使用什么?

So far so good, but I now need to set the LayoutParams of the view. What LayoutParams should I choose? I know that in a RelativeLayout you use a RelativeLayout.LayoutParams and in a LinearLayout you use a LinearLayout.LayoutParams. But what should I use in a dialog?

推荐答案

根据源代码此处,alertdialog的根元素是 LinearLayout ,所以我建议使用 LinearLayout.LayoutParams

According to the source code here , alertdialog's root element is a LinearLayout, so I would suggest using LinearLayout.LayoutParams

这篇关于AlertDialog中应使用哪些LayoutParams?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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