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);
}
});
CodePudding user response:
It can be done using setColorFilter(color).
CodePudding user response:
Try to change color of icon programatically with
Test.setColorFilter(ContextCompat.getColor(YourActivity.this, R.color.red));
CodePudding user response:
you change the tint of drawable like that:
imageView.setColorFilter(context.getResources().getColor(R.color.yourColor), PorterDuff.Mode.SRC_IN);