我有TextView
包含DrawableRight
,我想要做的是检测用户何时在drawableRight中按下该图标,这可能吗?如果是我该怎么办?
PS:我在片段中工作
TextView XML
<TextView
android:id="@+id/mTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="false"
android:textSize="22dp"
android:drawableRight="@mipmap/icn" //this is the drawable
/>
答案 0 :(得分:0)
mTitle.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_RIGHT = 2;
if (event.getAction() == MotionEvent.ACTION_UP) {
if (event.getRawX() >= (mTitle.getRight() - mTitle.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
//drawable pressed
return true;
}
}
return false;
}
});