Use the InputMethodManager.hideSoftInputFromWindow()
This method is mentioned frequently on the internet such as on this stackoverflow post here:
You can think of the InputMethodManager as a system service that mediates between your application and any input method you might be trying to use (in this case the keyboard).
A slight modification to this method worked for me in the past as well. Passing the InputMethodManager.HIDE_NOT_ALWAYS flag instead of 0 closed the keyboard for me when the above options had all failed.
If you’d like the code from this example I’ve shared a sample project demoing each of these solutions over on