使textview匹配警报对话框的高度

时间:2014-01-31 21:08:54

标签: android textview android-alertdialog

我想做一个干净的alertdialog是textview匹配alertdialog的高度。

final Builder builder = new AlertDialog.Builder(this);  
                TextView msg = new TextView(this);
                msg.setText("The winner is Player " + Players.intFromPlayers(player));
                msg.setGravity(Gravity.CENTER);
                msg.setLayoutParams(params);
                builder.setView(msg);
                builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) { 
                        finish();
                    }
                })

                .show();

enter image description here

2 个答案:

答案 0 :(得分:1)

如果你想要一个非常好看的alertdialog,你可以考虑使用padding,因为AlertDialog高度是动态创建的。

android:paddingTop="20dp"

顶部和文字之间的空间为20dp

答案 1 :(得分:0)

尝试将文字视图的高度设置为match_parent:

msg.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
相关问题