I'm currently struggling to combine navigation and closing the keyboard on button click. Right now I have a button which uses R.id.action.actionname to navigate to a new fragment. This is currently set in an onclick listener. If the user navigates to the new fragment, the keyboard stays open, which shouldn't be happening.
I've tried using the code below without success
val inputManager =
activity!!.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
val currentFocusedView = this.activity!!.currentFocus
binding.idLoginButton.setOnClickListener() {
if (currentFocusedView != null) {
inputManager.hideSoftInputFromWindow(
currentFocusedView.windowToken,
InputMethodManager.HIDE_NOT_ALWAYS
)
}
Navigation.createNavigateOnClickListener(R.id.action_homeFragment_to_loginFragment)
}
I've also tried putting
Navigation.createNavigateOnClickListener(R.id.action_homeFragment_to_loginFragment)
between the brackets of
binding.idLoginButton.setOnClickListener()
which also didn't work.