Formatting part of Textview in an event

Asked

Viewed 54 times

0

Speak guys, I apologize if the question is repeated, but is that I searched and could not solve my problem.

I need the following: The user enters with a String and the app returns another String just like it, but if there is any string repeated in the word it puts in bold and another color.

Ex: The user type "Canjica" the app returns "Canjica" but with the first "Ca" and the last "ca" in bold and other color, as they are identical sequences.

I already made the code to recognize the repeated sequences, I already have the position of the first and last sequence in the string and I already have the size of them.

Only I don’t know how to change Textview in parts, leaving only a few different parts.

Can anyone help me?? Thanks Galeta

1 answer

1

To do this, you do not need to edit Textview but to insert code into its text, using the following example:

String sourceString = "<b>" + texto+ "</b> " + texto; 
mytextview.setText(Html.fromHtml(sourceString));

outworking

text text

or Unicode characters

  • Aaah cool, then I’ll mount the String as I want at the time of the event and only then I give the . set in Textview?

  • Yes, it will render as if it were a web element, using Unicode characters do not need to put Html inside setText.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.