I have a single edit text. I want that when the user is done with it, to clear it's focus.
Follwoinf all the answers here I've made the parent focusable and I clear the focus of my edit text when needed. The problem is that though it is not in focus anymore, the keyboard remains open because now the parent is in focus. For the user it makes no sense that the keyboard is still open.
**to be clear, I am using a method to dismiss the keyboard. It always works but doesn't work now, probably because what I've mentioned above.
Is there a way to remove focus AND close the keyboard?
This is the method I use to dismiss the keyboard.
fun closeKeyboard(activity: Activity) {
val view = activity.currentFocus
if (view != null) {
val imm = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
imm!!.hideSoftInputFromWindow(view.windowToken, InputMethodManager.HIDE_IMPLICIT_ONLY)
}
}