我正在使用 Java 在 Android 2.2 上进行开发。我在 PopupWindow 上放置了一个 editText,但它不起作用。它就像一个禁用的编辑文本,点击编辑文本不会显示软键盘。如何在弹出窗口上添加编辑文本?
问问题
41330 次
5 回答
47
你试一试:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Title");
alert.setMessage("Message");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Do something with value!
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
于 2011-08-23T12:39:12.990 回答
18
我已经解决了这样的问题:我放了popupWindow.setFocusable(true);
它,现在它正在工作。似乎弹出窗口上的编辑文本没有焦点,因为弹出窗口没有焦点。
于 2010-11-11T06:24:23.193 回答
0
EditText 是否肯定将 android:editable 属性设置为 true?如果它是错误的,它将按照您的描述被禁用。
于 2010-11-09T15:15:31.233 回答
0
popWindow.setFocusable(true);
popWindow.update();
它会起作用的。
于 2015-04-03T07:05:21.103 回答
0
从任何侦听器调用此代码
private void popUpEditText() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Comments");
final EditText input = new EditText(this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
input.setLayoutParams(lp);
builder.setView(input);
// Set up the buttons
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do something here on OK
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}
于 2017-11-02T07:42:06.137 回答