【发布时间】:2019-11-16 12:55:06
【问题描述】:
我有一个工作正常的编辑文本,但在关闭对话框后,尽管编辑文本已聚焦并显示光标,但键盘未显示
我搜索了很多,并尝试了许多没有解决我的问题的解决方案
我尝试了这些方法,但它们不起作用
public void showKeyboard(){
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
public void closeKeyboard(){
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}
并尝试将它们添加到可运行文件中
【问题讨论】:
-
您能否发布您正在使用的与关闭对话框和使用 EditText 相关的代码?
-
请在警报对话框中显示您的代码。
-
@cpgreen2 和@Beverly Castillo 对话框是自定义的,并在其构造函数中扩展了 AppCompatDialog ``` if (this.getWindow() != null) { this.getWindow().setBackgroundDrawable(new ColorDrawable(颜色.透明)); this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); this.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); } ``` 它包含一个取消按钮来关闭 ``` cancelButton.setOnClickListener(view -> dismiss()); ```
标签: android android-edittext keyboard focus