0

I showed the icons in the program via ImageView. The yellow icons should turn red when the button is pressed. I tried all the methods, but none of them worked. ...Backgroundcolor... He turned ImageView red in full square shape. I just want the icon to change color. This is very difficult‚ Please help. Thank you.

My code:

ImageView Test = (ImageView) findViewById(R.id.TestImageIcon);
button2.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // Here            
        Test.setcolor(R.id.red);
    }
});
Abhimanyu
  • 11,351
  • 7
  • 51
  • 121
  • 1
    Provide a [minimal-reproducible-example](https://stackoverflow.com/help/minimal-reproducible-example) – Abhimanyu Nov 16 '21 at 06:47
  • Please post the code where you face an issue. Please make sure to post a [mre]. – kiner_shah Nov 16 '21 at 06:47
  • Does this answer your question? [Change the color of the icon in the ImageView in the java class](https://stackoverflow.com/questions/69948747/change-the-color-of-the-icon-in-the-imageview-in-the-java-class) – Abhimanyu Nov 16 '21 at 06:48
  • Kindly improve the [existing question](https://stackoverflow.com/q/69948747/9636037) if you are not getting any answers. Don't post a duplicate question. – Abhimanyu Nov 16 '21 at 06:49
  • 1
    Does this answer your question? [How to set color for imageview in Android](https://stackoverflow.com/questions/38653357/how-to-set-color-for-imageview-in-android) – Nitish Nov 16 '21 at 07:00
  • Please refer to [tag info](https://stackoverflow.com/questions/tagged/android-studio) if you are not sure, "Do NOT use for questions about programming for Android in general; instead, use the [android] tag.". This question is not related to `android-studio`. – Abhimanyu Nov 16 '21 at 08:53

3 Answers3

0

It can be done using setColorFilter(color).

Mahmoud Afarideh
  • 306
  • 4
  • 20
0

Try to change color of icon programatically with Test.setColorFilter(ContextCompat.getColor(YourActivity.this, R.color.red));

Android
  • 82
  • 1
  • 8
0

you change the tint of drawable like that:

 imageView.setColorFilter(context.getResources().getColor(R.color.yourColor), PorterDuff.Mode.SRC_IN);