0

I easily have one TextView on my app. How does it work to change the color of only one letter in the TextView?
Is it possible to adjust it only in the XML?

flx
  • 14,146
  • 11
  • 55
  • 70
  • 1
    You can use a SpannableString for this purpose. http://stackoverflow.com/questions/19908547/create-clickable-link-in-text-view-in-android. the answer in the link should give you a clue. – Raghunandan Feb 23 '14 at 15:35

1 Answers1

1

use SpannableString like:

SpannableString redSpannable= new SpannableString("string");
redSpannable.setSpan(new ForegroundColorSpan(Color.RED), 0, index, index+1);

set redSpannable to textview

vipul mittal
  • 17,343
  • 3
  • 41
  • 44
  • 1
    Downvote because it should have been flagged as (one of the many) duplicates http://stackoverflow.com/search?q=android+textview+change+color+part – Ben Pearson Feb 23 '14 at 15:44
  • What means index? Eclipse has the warning "Index cannot be resolved to a variable" – user3341325 Feb 23 '14 at 15:49
  • @BenPearson you can flag it as duplicate. But he is not copying the content from those posts. That should not be a reason to downvote as the post is not entirely incorrect. duplicate means simply flag the question and close it as duplicate – Raghunandan Feb 23 '14 at 17:01