kotlin - 如何在开始对话框中显示键盘
问题描述
当对话框打开时,键盘被隐藏。我想在对话框打开时自动显示键盘。
val mDialogView = LayoutInflater.from(this).inflate(R.layout.activity_profile_name_surname_dialog, null)
val mBuilder = AlertDialog.Builder(this).setView(mDialogView).setTitle("Change Name and Surname")
val mAlertDialog = mBuilder.show()
解决方案
你可以这样。它将强制打开键盘。
{
val mDialogView = LayoutInflater.from(this).inflate(R.layout.activity_profile_name_surname_dialog, null)
val mBuilder = AlertDialog.Builder(this).setView(mDialogView).setTitle("Change Name and Surname")
val mAlertDialog = mBuilder.show()
mDialogView?.let { v ->
val imm = context?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm?.let { it.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0) }
}
}
推荐阅读
- react-native - React Native:ComponentDidMount 不会更新 AsyncStorage.getItem
- java - Spring Maven Controller 找不到我的 JSP 页面
- cassandra - Cassandra 错误:TNegitiatingServerTransport.java:508 - 无法打开服务器传输
- javascript - 缩放内容向下滚动
- vb.net - 比较 ListViewItems 和 SelectedItems
- react-native - 如何使用参考连接
- java - Java,程序读取文件,输出是符号
- intellij-idea - IntelliJ Idea ctrl+shift+enter 在 Dart 和 Flutter 项目中工作奇怪
- python - Tensorflow BahdanauAttention - 层 memory_layer 需要 1 个输入,但它接收到 2 个输入张量
- swift - 快速 json 解析,没有 json 对象的标题