I have a Spannable Object
with a Clickable Object
set to it. When the Spannable String
is displayed in the TextView
it has bl
Override updateDrawState method of ClickableSpan class
String mystring =" Hello";
SpannableString ss= new SpannableString(mystring);
ss.setSpan(new MyClickableSpan(mystring), 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
class MyClickableSpan extends ClickableSpan{// extend ClickableSpan
String clicked;
public MyClickableSpan(String string) {
// TODO Auto-generated constructor stub
super();
clicked =string;
}
public void onClick(View tv) {
Toast.makeText(MainActivity.this,clicked ,
Toast.LENGTH_SHORT).show();
}
public void updateDrawState(TextPaint ds) {// override updateDrawState
ds.setUnderlineText(false); // set to false to remove underline
}
For changing color of spannable String
SpannableString ss = new SpannableString("android Stack Overflow");
ForegroundColorSpan fcs=newForegroundColorSpan(Color.parseColor("#01579B"));
ss.setSpan(fcs, 8,13, Spannable.SPAN_INCLUSIVE_INCLUSIVE);