I have a String.
String text= //Some String That I know
String textToBeColored = //Some Letter User enters at run time
How can I change the color of a specific letter that user enters at run time in my String.
I assume that you want something like particular text that user selects to be highlighted in the string. Below should help you do it.
String text = "abcada";
String textToBeColored = "a";
String htmlText = text.replace(textToBeColored,"<font color='#c5c5c5'>"+textToBeColored +"</font>");
// Only letter a would be displayed in a different color.
txtView.setText(Html.fromHtml(htmlText);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With