mardi 5 juillet 2016

Underline and change text color in Android TextView

I'm working on a kind of typing game on Android. It has a Text View with the sentence the user has to type in. Each time the current word the user has to type in will be underlined, once user finished a word, that word will change color based on the time it took to type (e.g. >5 seconds = red, <5 seconds is green).

My question is how can I underline and change the color of the words in the Text View so that when I underline a new word, it will also keep the color of the previous ones?

Currently I'm doing some thing like this every time I move to the next word

String texts = myTextView.getText().toString();
// put the next word to be underlined between <u> </u> tags
myTextView.setText(Html.fromHtml(texts));

As you can see, it will underline the next word but all of the colors of the previous words will be lost but I want to keep those.

Thanks for your help!

Aucun commentaire:

Enregistrer un commentaire