Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically change tint color of imageView? [duplicate]

Tags:

android

 <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

like image 604
sukesh Avatar asked Aug 23 '17 06:08

sukesh


1 Answers

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

like image 185
Abror Esonaliev Avatar answered Sep 27 '22 22:09

Abror Esonaliev