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?
Asked
Active
Viewed 67 times
2 Answers
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
-
-
Thanks everyone for your reply. A very special thanks to you @LuisAguilar – Jude Dec 07 '17 at 21:29