How to set color for imageview in Android

Android

Android Problem Overview


I want set icon into ImageView and i downloaded icons from this site : FlatIcon
Now i want set color to this icons but when use setBackground just add color for background and not set to icons!
When use NavigationView i can set color to icons with this code : app:itemIconTint="@color/colorAccent".

How can i set color to icons into ImageView such as itemIconTint ? Thanks all <3

Android Solutions


Solution 1 - Android

If you are using an icon maybe this can be useful:

android:tint="@color/colorAccent"

Otherwise you can try to modify the class:

ImageView imageViewIcon = (ImageView) listItem.findViewById(R.id.imageViewIcon);
imageViewIcon.setColorFilter(getContext().getResources().getColor(R.color.blue));

More info in this thread: Is it possible to change material design icon color from xml in Android?

Solution 2 - Android

Use tint attribute of ImageView.

 android:tint="@color/colorAccent"

Solution 3 - Android

 DrawableCompat.setTint(imageView.getDrawable(), ContextCompat.getColor(getApplicationContext(), R.color.white));

Solution 4 - Android

Use

imageView.setColorFilter(getResources().getColor(R.color.color_white)); 

Solution 5 - Android

Latest Lint shows a warning using android:tint, recommending to use app:tint, but the tint is not visible until you use it together with app:tintMode. So it looks like this:

app:tint="@color/yourcolor"
app:tintMode="add"

Solution 6 - Android

Use this tint imageview in android XML

 android:tint="@color/yourcolor"

Solution 7 - Android

Just use: ivMyImageView.setColorFilter(ActivityCompat.getColor(context, android.R.color.holo_green_light))

Solution 8 - Android

Just add this line in your image view.

In XML File:-

 android:tint="@color/color_name"

           or


app:tint="@color/color_name"

In Java File:-

imageViewIconName.setColorFilter(getContext().getResources().getColor(R.color.color_name));

Solution 9 - Android

You can simply use android:tint, but since there were some issues in some versions.

use AppCompatImageView and it will work fine.

<AppCompatImageView 
        android:tint="@color/your_color" />

Solution 10 - Android

app:tint="@color___"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMohammad NouriView Question on Stackoverflow
Solution 1 - AndroidEl0dinView Answer on Stackoverflow
Solution 2 - AndroidsJyView Answer on Stackoverflow
Solution 3 - AndroidDhara JaniView Answer on Stackoverflow
Solution 4 - AndroidSharanjeet KaurView Answer on Stackoverflow
Solution 5 - AndroidIgnacio Tomas CrespoView Answer on Stackoverflow
Solution 6 - AndroidShubhamhackzView Answer on Stackoverflow
Solution 7 - AndroidMiguel VieiraView Answer on Stackoverflow
Solution 8 - AndroidVikrant Singh RawatView Answer on Stackoverflow
Solution 9 - AndroidDrioueche MohammedView Answer on Stackoverflow
Solution 10 - AndroidDavidUpsView Answer on Stackoverflow