I have reffered this question and implemented circular background for TextView using circle.xml
(in res/drawable) and setting it as android:background="@drawable/circle"
for TextView. But what I need is , I need to set the background color dynamically through code. Just like the lollipop contacts app as shown below
How can I acheive this? I need the TextView background in circular shape always as shown in above image
You can change TextView background color in many ways like:
or
or
or
and many other ways too...
Edit:
If you want to change your TextView background color that was defined in your drawable file, do it like this:
GradientDrawable:
StateListDrawable:
But if you don't want to set a color filter, you can get the drawable of each state separately by following the answer in this link.