Is there a way we can set a custom drawable (from resources) to a span, especially a ClickSpan, of TextView?
Google returns many answers for disabling highlights or changing colors etc by overriding updateDrawState() of the span, but I do not see how one can set a drawable to the background.
I see a possibility in DynamicDrawableSpan, but I am unable to make it work along with ClickableSpan. This is my code:
public class MyDynamicDrawableSpan extends DynamicDrawableSpan
{
private Context c;
public MyDynamicDrawableSpan(Context context) {
super();
c = context;
}
@Override
public Drawable getDrawable() {
Resources res = c.getResources();
Drawable d = res.getDrawable(R.drawable.span_background);
return d;
}
}
And this is how I use it:
SpannableStringBuilder ssb = new SpannableStringBuilder(text);
MyDynamicDrawableSpan ddSpan = new MyDynamicDrawableSpan(getApplicationContext());
...
ssb.setSpan(ddSpan, start, end, 0);
ssb.setSpan(new ClickableSpan(...
This does not work. It only helps to make the span invisible. Any bright ideas?