Reputation: 15734
I have a LinearLayout like this:
<LinearLayout
android:background="@drawable/circle"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:id="@+id/powerCircle"
android:layout_width="20dp"
android:layout_height="20sp" />
Then I have a background of a colored circle, like this:
circle.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#666666"/>
<size
android:width="20dp"
android:height="20dp"/>
</shape>
In my custom adapter
I want to change the background color of the circle based on a status variable.
How do I get a reference to the circle's
background?
Upvotes: 4
Views: 2860
Reputation: 15824
Perhaps, something like this should work:
GradientDrawable background = (GradientDrawable) linearView.getBackground();
background.setColor(getResources().getColor(R.color.some_color));
Upvotes: 8