Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color of circle in LinearLayout

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?

like image 944
TheLettuceMaster Avatar asked Oct 18 '25 15:10

TheLettuceMaster


1 Answers

Perhaps, something like this should work:

GradientDrawable background = (GradientDrawable) linearView.getBackground();
background.setColor(getResources().getColor(R.color.some_color));
like image 66
AndroidEx Avatar answered Oct 21 '25 05:10

AndroidEx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!