Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the keyboard when I click on EditText?

Tags:

android

kotlin

Hello I would like to do the next thing : when I click on an EditText I would like to hide the keyboard but seeing the cursor. I tried to do this :

    editText_test!!.setCursorVisible(false);
    editText_test!!.setFocusableInTouchMode(false);
    editText_test!!.setFocusable(true);

Obviously I don't see the keyboard but I can't click on my EditText. How can I do this ? To be precise I am using Kotlin.

Thank you !

like image 460
Guy Martino Avatar asked Dec 23 '22 15:12

Guy Martino


1 Answers

If you have minimum API >= 21:

editText_test!!.showSoftInputOnFocus = false

To deal with different versions:

if (Build.VERSION.SDK_INT >= 21) {
    editText_test!!.showSoftInputOnFocus = false
} else if (Build.VERSION.SDK_INT >= 11) {
    editText_test!!.setRawInputType(InputType.TYPE_CLASS_TEXT)
    editText_test!!.setTextIsSelectable(true)
} else {
    editText_test!!.setRawInputType(InputType.TYPE_NULL)
    editText_test!!.isFocusable = true
}
like image 152
BakaWaii Avatar answered Dec 28 '22 07:12

BakaWaii