How to Change image color dynamically in android?

Here’s how I do this: It’s pulling the color from a resource xml file.

<resources>
<color name="new_color">#FFAAAAAA</color>
</resources>

In your activity .java file:

import android.graphics.PorterDuff.Mode;

Resources res = context.getResources();
final ImageView image = (ImageView) findViewById(R.id.imageId);
final int newColor = res.getColor(R.color.new_color);
image.setColorFilter(newColor, Mode.SRC_ATOP);

To clear it call:

image.setColorFilter(null);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)