How to make TextView shape circle and set different background color based on condition

后端 未结 5 1200
死守一世寂寞
死守一世寂寞 2020-12-08 08:09

I have a TextView, what I want is to make the TextView shape circle and then set different background colors based on different conditions I have u

5条回答
  •  醉话见心
    2020-12-08 08:20

    If you have a relatively small amout of colors, you can create a drawable file for each color, for example create a file bg_red.xml:

    
    
      
          
          
      
    
    

    Then assign define the TextView:

    
    

    Note that the width is twice the radius of the background corner radius.

    To change the color from code:

    TextView v = (TextView) findViewById(R.id.my_text_view);
    v.setBackgroundResource(R.drawable.bg_blue);
    

提交回复
热议问题