我想用 EditText 元素打开 AlertDialog,以便显示键盘并选择整个文本?
这就是我尝试的方式:
public void showRenameDialog(Task task) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Enter the title of Task");
final EditText input = new EditText(this);
input.setId(TEXT_ID);
input.setText(task.getTitle());
input.setSelectAllOnFocus(true);
builder.setView(input);
final Task t = task;
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
...
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
return;
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);
}
选择了文本,但未显示键盘。
Ant 当我触摸文本时,键盘打开,但不再选择文本。