How to set color for imageview in Android

前端 未结 7 1623
囚心锁ツ
囚心锁ツ 2021-01-30 19:47

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

相关标签:
7条回答
  • 2021-01-30 20:29

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

    0 讨论(0)
  • 2021-01-30 20:30
     DrawableCompat.setTint(imageView.getDrawable(), ContextCompat.getColor(getApplicationContext(), R.color.white));
    
    0 讨论(0)
  • 2021-01-30 20:32

    Use tint attribute of ImageView.

     android:tint="@color/colorAccent"
    
    0 讨论(0)
  • 2021-01-30 20:32

    Use this tint imageview in android XML

     android:tint="@color/yourcolor"
    
    0 讨论(0)
  • 2021-01-30 20:32

    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"
    
    0 讨论(0)
  • 2021-01-30 20:34

    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?

    0 讨论(0)
提交回复
热议问题