I make a simple client tweeter and run into a problem. In the tweet text there are mentions about the user, for example: @ user98 how to make it stand out in the text and be clickable?
1 answer
You need to use the Spannable interface. It is intended for styling text. For example:
Adding marking is carried out by the method:
Spannable.setSpan(Object span, int start, int end, int flags); Deletion, respectively, by the method:
Spannable.removeSpan(Object span); Text selection example:
// Create spannable text and set style. Spannable text = new SpannableString("This is underline and bold text."); text.setSpan(new UnderlineSpan(), 8, 17, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); text.setSpan(new StyleSpan(Typeface.BOLD), 22, 26, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // Set spannable text in TextView. TextView textView = (TextView) findViewById(R.id.text); textView.setText(text); Here is a good article on this topic in Russian - http://developer.alexanderklimov.ru/android/theory/spannable.php
- For clickability, appropriately, ClickableSpan along with UnderlineSpan and / or with other spans. - Andrew Grow
|
