【发布时间】:2015-10-16 12:58:02
【问题描述】:
我有一个EditText 对象:
EditText textbox = new EditText (this);
textbox.setHint (something);
我想使用构建器将此视图添加到AlertDialog。
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),这也是我通过代码创建视图的原因。
到目前为止一切顺利,但我现在需要设置视图的LayoutParams。我应该选择什么LayoutParams?我知道在RelativeLayout 中你使用RelativeLayout.LayoutParams 而在LinearLayout 中你使用LinearLayout.LayoutParams。但是我应该在对话框中使用什么?
【问题讨论】:
-
你不需要以编程方式创建布局来使用你知道的 setView 吗?
标签: java android android-layout dialog