Android EditText: How to disable cursor move on touch?

前端 未结 7 2146
长情又很酷
长情又很酷 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:09

    public class MyEditText extends EditText{
    
        @Override
        public boolean onTouchEvent(MotionEvent event)
        {
             final int eventX = event.getX();
             final int eventY = event.getY();
             if( (eventX,eventY) is in the middle of your editText)
             {
                  return false;
             }
             return true;
        }
    }
    

    This will "disable" tapping in the middle of your edit text

提交回复
热议问题