javaandroidimageview

Change the color of the icon in the ImageView in the java class


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);
    }
});

Solution

  • you change the tint of drawable like that:

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