0

I have a custom view which extends TextView and the background is a drawable,

<CustomView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/circile_background" />

and want to change the background color in custom view

public class CustomView extends TextView {

    TypedArray typedArray;

    public CustomView (Context context) {
        super(context);
    }

    public CustomView (Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    public void setColorLevel(int color) {
       // update color here
    }
}
A-Sharabiani
  • 17,750
  • 17
  • 113
  • 128
Xianwei
  • 2,381
  • 2
  • 22
  • 26

1 Answers1

1

check similar question here How to change colors of a Drawable in Android?

public void setDangerLevel(int color) {
    Drawable drawable=this.getBackground().getCurrent();
    drawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
    }
svkaka
  • 3,942
  • 2
  • 31
  • 55