我已经研究了很多关于 SO 的答案,并提出了以下代码来在我的对话框弹出时显示键盘:
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Title");
final EditText input = new EditText(this);
input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean focused) {
alertDialog
.getWindow()
.setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
});
input.setFocusable(true);
input.requestFocus();
alertDialog.setView(input);
alertDialog.show();
对话框显示,但键盘没有弹出。如果这有所不同,这一切都在 onTouch(...) 方法中。
我的应用程序仅是横向模式。我发现在纵向模式下,它正在显示。为什么是这样?
任何帮助表示赞赏。