Reputation: 6881
I have an ImageView
with the source being an ImageAsset
.
My image is a circle with a plus and I am looking to colour the inside of the circle only. How do I do that?
Using setBackgroundColor
colours the whole of the view thus giving a square background like this:
Upvotes: 0
Views: 4067
Reputation: 6849
You can apply a color tint to your ImageView
. This will not affect your background if it's transparent, just the colored part (which is the circle and the plus)
imageView.setColorFilter(ContextCompat.getColor(context, R.color.COLOR_YOUR_COLOR),
android.graphics.PorterDuff.Mode.MULTIPLY);
Update
Using android.graphics.PorterDuff.Mode.SRC_IN
will also work (if you don't need to multiply the source and destination pixels)
Update 2
Since the destination part is not colored than the best solution is to use VectorDrawable
.
You can use VectorChildFinder to find inner parts of your SVG resource and change its color.
VectorChildFinder vector = new VectorChildFinder(this, R.drawable.my_vector, imageView);
VectorDrawableCompat.VFullPath path1 = vector.findPathByName("path1");
path1.setFillColor(Color.RED);
imageView.invalidate();
to create your SVG, follow these steps :
Upvotes: 1