Android:如何在专注于 EditText 时隐藏/显示键盘?
我有注册表单,当用户聚焦于 EditText
时,我需要显示键盘。我一直遇到这个问题,我使用了很多不再有效的解决方法。令我惊讶的是,Android 无法处理这种基本的事情,比如单独在 EditText
之间进行聚焦。
这里发生了什么:当我从电子邮件 EditText 移动到密码一时,它将隐藏键盘,并且密码字段聚焦,指示器闪烁,而没有可见的键盘。
代码:
emailEt.apply {
onFocusChange {
if (isFocused) app.showKeyboard(a) else app.hideKeyboard(this)
}
onEditorAction {
passwordEt.requestFocus()
}
afterTextChanged {
emailFieldValidation(true)
validateData()
}
}
passwordEt.apply {
onFocusChange {
if (isFocused) app.showKeyboard(a) else app.hideKeyboard(this)
}
onEditorAction {
this.clearFocus()
}
afterTextChanged {
passwordFieldValidation(true)
validateData()
}
}
resetData()
emailEt.requestFocus()
I have registration form and I need to show keyboard when user is focused in EditText
. I had always problem with this and I used a lot of workarounds which are no longer working. Im surprised Android cant handle this basic thing like focusing between EditText
on its own.
What is happening here: When I move from email EditText to password one, it will hide keyboard and password field is focused with indicator blinking without visible keyboard.
Code:
emailEt.apply {
onFocusChange {
if (isFocused) app.showKeyboard(a) else app.hideKeyboard(this)
}
onEditorAction {
passwordEt.requestFocus()
}
afterTextChanged {
emailFieldValidation(true)
validateData()
}
}
passwordEt.apply {
onFocusChange {
if (isFocused) app.showKeyboard(a) else app.hideKeyboard(this)
}
onEditorAction {
this.clearFocus()
}
afterTextChanged {
passwordFieldValidation(true)
validateData()
}
}
resetData()
emailEt.requestFocus()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Java
Kotlin
Java
Kotlin