The following code shows how I'm applying a pressed state using a custom ClickableSpan and selector. However, the pressed state is applied whenever I press anywhere on the TextView, not just the ClickableSpan. How do I stop this?
Note: it does not call onClick
, but does apply state_pressed
from the selector. I want it to do neither.
MyView.java
SpannableString spanned = new SpannableString("click here");
spannable.setSpan(new MyClickableSpan() {
@Override
public void onClick(View widget) {
doSomething();
}
}, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(spanned);
textView.setMovementMethod(LinkMovementMethod.getInstance());
MyClickableSpan.java
public abstract class MyClickableSpan extends ClickableSpan {
@Override
public abstract void onClick(View view);
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
}
the TextView
<TextView
android:id="@+id/my_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textColorLink="@color/my_selector" />
my_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/my_color_pressed" />
<item android:color="@color/my_color" />
</selector>
Edit note: Added TextView code