etPhoneNum.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// et.getCompoundDrawables()得到一个长度为4的数组,分别表示左右上下四张图片
Drawable drawable = etPhoneNum.getCompoundDrawables()[2];
//如果右边没有图片,不再处理
if (drawable == null)
return false;
//如果不是按下事件,不再处理
if (event.getAction() != MotionEvent.ACTION_UP)
return false;
if (event.getX() > etPhoneNum.getWidth()
- etPhoneNum.getPaddingRight()
- drawable.getIntrinsicWidth()){
etPhoneNum.setText("");
etPhoneNum.setCompoundDrawablesWithIntrinsicBounds(0,0,0,0);
}
return false;
}
});