0

I am create an android app with android studio that retrieves text from mysqli database using volley library into a text view. I want to check if the text contains "@" and if to does it it should be coloured red. That Is, I want only the "@" to be changed. Please guys how will I achieve that?

Jude
  • 41
  • 7

2 Answers2

0

use an if statement like

if text.contains("@") {
text.setTextColor(Color.RED);
}

read here How to set the text color of TextView in code? to learn more about changing text color

petyr
  • 415
  • 7
  • 15
0

This will change the color of only one word in this case "@"

Esto cambiara el color de una sola letra, en este caso "@"

String newText = String.valueOf(text.getText()).replace("@","<font color='#fff0000'>@</font>");
        text.setText(Html.fromHtml(newText));
Luis Aguilar
  • 645
  • 9
  • 26