Hide Keyboard Kotlin Android Studio

Last Updated on November 10, 2022 by Humera hallari

This code will hidden your keyboard in your Android device while use this. You can just copy paste this kotlin command in your android program.

 //Hide our Keyboard
    fun hideMyKeyboard(){
        val view = this.currentFocus
        if (view != null){
            val hideMe = getSystemService( Context.INPUT_METHOD_SERVICE) as InputMethodManager
            hideMe.hideSoftInputFromWindow(view.windowToken, 0)
        }
        //else
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
    }

How to use, just call:

hideMyKeyboard()

Leave a Comment