Change Fill Color on Vector Asset in Android Studio

Change fill color on vector asset in Android Studio

Don't edit the vector assets directly. If you're using a vector drawable in an ImageButton, just choose your color in android:tint.

<ImageButton
android:layout_width="48dp"
android:layout_height="48dp"
android:id="@+id/button"
android:src="@drawable/ic_more_vert_24dp"
android:tint="@color/primary" />

changing vector drawable color

Use this class

private class VectorDrawableUtils {

Drawable getDrawable(Context context, int drawableResId) {
return VectorDrawableCompat.create(context.getResources(), drawableResId, context.getTheme());
}

Drawable getDrawable(Context context, int drawableResId, int colorFilter) {
Drawable drawable = getDrawable(context, drawableResId);
drawable.setColorFilter(ContextCompat.getColor(context, colorFilter), PorterDuff.Mode.SRC_IN);
return drawable;
}

}

And call it like this

 new VectorDrawableUtils().getDrawable(mContext,R.drawable.x,R.color.black); 

how to change the color of vector asset in FloatingActionButton?

try this with app:srcCompat and app:tint:

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/white"
android:focusable="true"
app:srcCompat="@drawable/ic_camera_24"
app:tint="@color/green"
app:fabSize="mini"
app:rippleColor="@color/green" />

src: https://material.io/components/buttons-floating-action-button/android#mini-fabs

How to change color of vector drawable path on button click

Use this to change a path color in your vector drawable

VectorChildFinder vector = new VectorChildFinder(this, R.drawable.my_vector, imageView);

VectorDrawableCompat.VFullPath path1 = vector.findPathByName("path1");
path1.setFillColor(Color.RED);

Library is here: https://github.com/devsideal/VectorChildFinder

Android - How to change the color of Vector Asset?

First of all, If you use vector on drawableLeft, drawableRigth, etc.. ,Vectors will crash your application for pre-lollipop devices.
You can use this : https://github.com/bsobe/vectorview

Also, You can change hex colors in xml of the vector asset manually.



Related Topics



Leave a reply



Submit