How To Set And Get Tint Color On Svg Programmaticaly In Android?
I have an ImageView which has an SVG as source example: android:src='@drawable/bold_svg'. Now on click I want to set the tint color to color accent or return it to white. Two state
Solution 1:
I managed to find the answer something like this would work:
myImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int currentColor, colorAccent;
currentColor=ImageViewCompat.getImageTintList(myImageView).getDefaultColor();
colorAccent=getResources().getColor(R.color.colorAccent);
if (currentColor==colorAccent) {
ImageViewCompat.setImageTintList(ivBold, ColorStateList.valueOf(ContextCompat.getColor(getApplicationContext(), R.color.white_text_color)));
} else {
ImageViewCompat.setImageTintList(myImageView, ColorStateList.valueOf(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent)));
}
}
});
Post a Comment for "How To Set And Get Tint Color On Svg Programmaticaly In Android?"