是否可以在设计器中声明为drawableleft的drawable上添加OnClickListener
android:drawableLeft="@drawable/ic_password"
或者有没有办法在EditText的左侧添加ImageView
解决方法:
对于drawableleft点击监听器:
editText.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_LEFT = 0;
final int DRAWABLE_TOP = 1;
final int DRAWABLE_RIGHT = 2;
final int DRAWABLE_BOTTOM = 3;
if(event.getRawX() <= (editText.getCompoundDrawables()[DRAWABLE_LEFT].getBounds().width()))
{
// your action here
return true;
}
return false;
}
});
如果你想要点击监听器可绘制正确使用以下条件
if(event.getAction() == MotionEvent.ACTION_UP) {
if(event.getRawX() >= (editComment.getRight() - editComment.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width()))