我无法在我的 AlertDialog 中看到“我的数据”,因为它与 EditText 重叠。
Context context = MyActivity.this;
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle(" NEW TITLE");
alert.setMessage("MESSAGE 1");
final TextView tx = new TextView(this);
tx.setText("MY DATA");
alert.setView(tx);
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked OK so do some stuff */
}
});
alert.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked Cancel so do some stuff */
}
});
alert.create();
alert.show();
最佳答案
试试这个:
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(Vertical);
final TextView tx = new TextView(this);
tx.setText("MY DATA");
layout.addView(tx);
// Set an EditText view to get user input
final EditText input = new EditText(this);
layout.addView(input);
alert.setView(layout);
关于android - TextView 和编辑文本的警告对话框间距问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5549372/