I use a vector that can be done in my code. Based on some state, I need to change the color of the paint. Using the code below to achieve it.
Drawable drawable = VectorDrawableCompat.create(context.getResources(),
R.drawable.icon_vector_star, null);
if(drawable != null) {
drawable = drawable.mutate();
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable,
ContextCompat.getColor(context, R.color.grey));
DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
imageView.setImageDrawable(drawable);
} else {
Log.e(LOG_TAG, "Error while creating vector drawable");
}
Is there any performance impact in doing so? Should I use a different vector can I make a different color and just set it? Please suggest.
source
share