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
I'M Getting a Nullpointerexception When I Use Action_Image_Capture to Take a Picture
Android Attaching Multiple Adapters to One Adapter
Import .R Cannot Be Resolved When I Import Actionbarsherlock
How to Make a Phone Number Clickable on an iPhone or Android Phone to Make a Call in HTML
How to Read the Sd Card Id Number
Mobile Keyboard Pushes Up Content Because of an Absolutely Positioned Drawer
Play Youtube HTML5 Embedded Video in Android Webview
Using Multiple Text Colors in Android's Textview [ HTML.Fromhtml() ]
Call an Activity Method from a Broadcastreceiver Class
Android Browser Bug? Div Overflow Scrolling
Android Webview HTML5 Video Autoplay Not Working on Android 4.0.3
How to Record Audio on Webpage (iOS, Android, Pc/Mac) - No Flash
Textinputlayout Hint Doesn't Float Up After Updating Google Support Library
Save Webview Content to Android Storage and Load It
Get Color Value Programmatically When It's a Reference (Theme)