Disable soft-keyboard from EditText but still allow copy/paste?

后端 未结 7 1620
误落风尘
误落风尘 2020-11-28 06:39

Hi I\'m making custom dialer so I create my own input pad.

The problem is how do I disable the EditText but still allow cut/copy/paste?

7条回答
  •  遥遥无期
    2020-11-28 07:20

    Had a similar need due to my custom inline "fake" input which was still visible as the os soft keypad was appearing after focus moved to an edit text. Solution was to make the edit text hide soft input until the previous custom input widget had finished its edit lifecycle.

    Used @Bruce's answer for inspiration, also saw a few related posts which I'll attach at end. Solution I found worked was:

    fun setInputType(inputType: Int) {
            getEditText().setRawInputType(inputType)
            if (inputType == InputType.TYPE_NULL) {
                getEditText().setTextIsSelectable(true)
                getEditText().isCursorVisible = true
            }
        }
    

    had to use setRawInputType() instead as multiline text input was not respected when setting from InputType.TYPE_NULL back to InputType.TYPE_TEXT_FLAG_MULTI_LINE.

    Seems there are users reporting issues relating to calling setInputType(InputType.TYPE_NULL). see: https://issuetracker.google.com/issues/36907992

    other useful related posts:

    How to make EditText not editable through XML in Android?

    EditText non editable

提交回复
热议问题