There is for example the text "10/5" and how to make it in TextView so that for example the number 10 was green, the slash is gray, and the number 5 is red
2 answers
You can avoid using HTML with this method:
TextView TV = (TextView)findViewById(R.id.mytextview01); Spannable word = new SpannableString("Your message"); word.setSpan(new ForegroundColorSpan(Color.BLUE), 0, word.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); TV.setText(word); Spannable wordTwo = new SpannableString("Your new message"); wordTwo.setSpan(new ForegroundColorSpan(Color.RED), 0, wordTwo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); TV.append(wordTwo); |
TextView supports simple HTML tags, like <font> . You can use it like this:
textView.setText(HTML.fromHtml("<font color='#00ff00'>10</font><font color='#555555'>/</font><font color='#ff0000'>5</font>")); - When using this approach, do not forget to disable the use of userscript with the Html.escapeHtml command (textView.getText (). ToString ()) - Ruslan Kucherenko
|