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;
}
});
【android】给EditText的drawable添加点击事件
猜你喜欢
转载自blog.csdn.net/yonghuming_jesse/article/details/97389210
今日推荐
周排行