Android EditText: How to disable cursor move on touch?

前端 未结 7 2156
长情又很酷
长情又很酷 2021-02-08 07:42

I have EditText which displays something like ###-###. I want the user to be able to change this text only from the 1st position onward. That is user should not be able to touch

7条回答
  •  死守一世寂寞
    2021-02-08 08:10

    this solution also prevents a touch and drag, apart from click

           //don't allow user to move cursor
           editText.setOnTouchListener { view, motionEvent ->
                if (motionEvent.action == MotionEvent.ACTION_UP) {
                    editText.setSelection(editText.text.length)
                }
                return@setOnTouchListener true
            }
    

提交回复
热议问题