[英]Android: How to hide/show keyboard while focused on EditText?
I have registration form and I need to show keyboard when user is focused in EditText
.我有注册表单,当用户专注于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.我很惊讶 Android 不能处理这个基本的事情,比如在EditText
之间单独聚焦。
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.这里发生了什么:当我从 email EditText 移动到密码一时,它将隐藏键盘并且密码字段集中在指示器闪烁而没有可见键盘的情况下。
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()
Java Java
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
Kotlin Kotlin
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.