在我的应用程序中,我有一个带有 EditText 的对话框。我想自动获取编辑框的键盘。即,当显示对话框时,应该显示键盘。有什么方法可以在不触摸 EditText 的情况下显示键盘。
我添加了对话框代码
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(APP_NAME);
builder.setMessage(message);
// Use an EditText view to get user input.
final EditText inputDevice = new EditText(this);
final EditText inputTester = new EditText(this);
if (id == DLG_ID_TESTER) {
inputTester.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
// inputTester.setThreshold(1);
inputTester.setSelectAllOnFocus(true);
inputTester.requestFocus();
inputTester.setId(TXT_ID);
builder.setView(inputTester);
} else {
inputDevice.setId(TXT_ID);
inputDevice.setSelectAllOnFocus(true);
builder.setView(inputDevice);
}
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
if (id == DLG_ID_TESTER) {
String val = inputTester.getText().toString();
testerName = val;
txtTesterName.setText(testerName);
} else if (id == DLG_ID_DEVICE) {
String value = inputDevice.getText().toString();
deviceId = value;
txtDeviceId.setText(deviceId);
}
return;
}
});
builder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
return;
}
});
return builder.create();
}