mSpannableString = new SpannableString("12:00PM");
mSpannableString.setSpan(clickableSpan, 0, 7, 0);
mSpannableString.setSpan(new StyleSpan(Typeface.BOLD), 0, 7, 0);
TextView textView = new TextView(getContext());
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setText(mSpannableString);
mCancelFrom.setText(getString(R.string.cancel_from_text) + " " + mSpannableString);
i need to set the text to bold and make it clickable. the above code i have written in a dialog. the string "12:00PM" is getting displayed. but there is not bold effect on it and it is not clickable. can you hel me with this?
SpannableString string = new SpannableString("Text with clickable text"); string. setSpan(new CustomClickableSpan(), 10, 19, Spanned. SPAN_EXCLUSIVE_EXCLUSIVE); Text with ClickableSpan .
For example, the StyleSpan can be used like this: SpannableString string = new SpannableString("Bold and italic text"); string. setSpan(new StyleSpan(Typeface. BOLD), 0, 4, Spannable.
SpannedString. This is the class for text whose content and markup are immutable. This is the interface for text that has markup objects attached to ranges of it. Not all text classes have mutable markup or text; see Spannable for mutable markup and Editable for mutable text.
Try This ,it may be help to you
SpannableString ss = new SpannableString("12:00PM");
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
startActivity(new Intent(SendSMS.this, SendSMS.class));
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
};
ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 7, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(clickableSpan, 0, 7, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mCancelFrom.setText(getString(R.string.cancel_from_text) + " " + ss);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With