How to close Android Soft KeyBoard programmatically?(Kotlin & Java)

How to hide soft keyboard on android with code?
Note: Emulator does not appear, try live on the phone.


//For Kotlin
val inputManager:InputMethodManager =getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputManager.hideSoftInputFromWindow(currentFocus.windowToken, InputMethodManager.SHOW_FORCED)
//For Java
InputMethodManager inputManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.SHOW_FORCED);
view raw hideKeyboard.kt hosted with ❤ by GitHub

Yorumlar

Bu blogdaki popüler yayınlar