How to change colors of a Drawable in Android? How to change colors of a Drawable in Android? android android

How to change colors of a Drawable in Android?


I think you can actually just use Drawable.setColorFilter( 0xffff0000, Mode.MULTIPLY ). This would set white pixels to red but I don't think it would affect the transparent pixels.

See Drawable#setColorFilter


Give this code a try:

ImageView lineColorCode = (ImageView)convertView.findViewById(R.id.line_color_code);int color = Color.parseColor("#AE6118"); //The color u want             lineColorCode.setColorFilter(color);


I know this question was ask way before Lollipop but I would like to add a nice way to do this on Android 5.+. You make an xml drawable that references the original one and set tint on it like such:

<?xml version="1.0" encoding="utf-8"?><bitmap    xmlns:android="http://schemas.android.com/apk/res/android"    android:src="@drawable/ic_back"    android:tint="@color/red_tint"/>