10
 <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

2

5 Answers 5

35

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));

in night mode in day mode

Sign up to request clarification or add additional context in comments.

Comments

6

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)

Comments

4

Try this,

imageViewDone.setColorFilter(ContextCompat.getColor(context, R.color.yourcolor), android.graphics.PorterDuff.Mode.MULTIPLY);

Comments

1

You can use Color Filter

  imageView.setColorFilter(ContextCompat.getColor(mContext, R.color.CHOICE_COLOUR), android.graphics.PorterDuff.Mode.MULTIPLY);

Comments

1

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) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.