0

Is it possible to have the textview load colors from xml based on its value. I did have a look at states but that didn't fulfill my needs. Let's say the background would change from red to green based on decimal value for the text (rating) ... zomato style ..

Any help is appreciated

i did try :

if (text < 1)
    holder.text.setTextColor(Color.RED);

And checks based on values to choose colors. But I would like to know if this can be done using xml and having a gradient.

textview background based on decimal content

lost_in_the_source
  • 10,998
  • 9
  • 46
  • 75
Hassan Khraibani
  • 303
  • 3
  • 11

1 Answers1

0

AFAIK, there is not a simple xml way to do this. You can try LevelListDrawable, change level by setLevel() or setImageLevel() in code.

  • Welcome to Stackoverflow Xiaoling. Appreciate you taking time and initiatives to answer, contribute to community. However, always make sure you search the platform for relevant questions and provide links to these resources in your answers. For this question, there is a relevant question with fairly strong solution here - https://stackoverflow.com/questions/10316354/how-to-make-text-view-shape-circle-and-set-different-background-color-based-on-c – Pruthvi Kumar Nov 21 '18 at 03:24
  • i did vote for your answer sadly it didnt show as am a new user .. i would accept it as an answer as soon i test it best regards :) – Hassan Khraibani Nov 23 '18 at 00:02