Handle ENTER button Kotlin Android Studio

Last Updated on November 10, 2022 by SanaModi

Sometimes you need to handle Enter button while make an application. To handle button in Kotlin Android Studio, you can just copy this kotlin code.

    //Handle Enter Button
    fun myEnter(){
        editText.setOnKeyListener(View.OnKeyListener{v, keyCode, event ->
            if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_UP){
               //Start your action
                Toast.makeText(this, "Hi there ! \n This is a Enter Event Button", Toast.LENGTH_LONG).show()
                //End action
                return@OnKeyListener true

How to use, just call:


Leave a Comment