I set tint color with tint mode multiply in Imageview xml and I want to change only tint color in from java in button click. I tried this

imageView.getBackground().setColorFilter(ContextCompat.getColor(MainActivity.this,R.color.blueish), PorterDuff.Mode.MULTIPLY); 

but it gave exception and I also tried this

imageView.setColorFilter(ContextCompat.getColor(MainActivity.this, R.color.blueish), android.graphics.PorterDuff.Mode.MULTIPLY);

but nothing happens

This is my xml code

    <ImageView
    android:id="@+id/imageview"
    android:layout_width="match_parent"
    android:tintMode="multiply"
    android:tint="#ffae"
    android:layout_height="580dp"
    android:src="@drawable/as"/>

1 Answers

0
Qasim On Best Solutions

You can use the following to set tint of your ImageView:

ImageViewCompat.setImageTintList(imageview, ColorStateList.valueOf(resources.getColor(R.color.red)));