<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/star_icon"
android:id="+@starid"/>
I need to change tint color of icon programmatically help me
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/star_icon"
android:id="+@starid"/>
I need to change tint color of icon programmatically help me
Thanks for Hardik, orginal answer
You can change the tint, quite easily in code via:
imageView.setColorFilter(Color.argb(255, 255, 255, 255));
If you want color tint then:
imageView.setColorFilter(ContextCompat.getColor(context,
R.color.COLOR_YOUR_COLOR));
with mode:
imageView.setColorFilter(ContextCompat.getColor(context,
R.color.COLOR_YOUR_COLOR), android.graphics.PorterDuff.Mode.MULTIPLY);
in my case:
imgBottomDivider.setColorFilter(ContextCompat.getColor(getContext(),
mPreferences.isNightMode() ? R.color.colorWhite : R.color.colorBlack));
use
imageView.setColorFilter(int color, PorterDuff.Mode mode)
or
imageView.setColorFilter(int color)
Reference: https://developer.android.com/reference/android/widget/ImageView.html#setColorFilter(int)
Try this,
imageViewDone.setColorFilter(ContextCompat.getColor(context, R.color.yourcolor), android.graphics.PorterDuff.Mode.MULTIPLY);
You can use Color Filter
imageView.setColorFilter(ContextCompat.getColor(mContext, R.color.CHOICE_COLOUR), android.graphics.PorterDuff.Mode.MULTIPLY);
If you want to use default Duff mode for the imagevview you can prefer to
imageView.setColorFilter(int color)
but if you want to change the colour duff like light to multiple or dark then you should use:
imageView.setColorFilter(int color, PorterDuff.Mode mode)