1

I'm having problems with my ImageView. Btw, I'm using CircularImageView which has a property app:selector_color.

This is the scenario. ImageView has a drawable (src). What I want to happen is when I click on the ImageView, I want to add tint to it.

This is what I've tried so far:

   viewHolder.ivProfile.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            result = data.get(position);

            int highlightColor = context.getResources().getColor(R.color.main_red_transparent);
            PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(highlightColor, PorterDuff.Mode.SRC_ATOP);

            CircularImageView ci = (CircularImageView) v;

            if (thumbnailsselection[position]) {
                ci.setSelected(false);
                thumbnailsselection[position] = false;
                viewHolder.tvTitle.setVisibility(View.GONE);
            } else {
                ci.setSelected(true);
                ci.getDrawable().setColorFilter(highlightColor, PorterDuff.Mode.SRC_ATOP);
                thumbnailsselection[position] = true;
                viewHolder.tvTitle.setVisibility(View.VISIBLE);
                viewHolder.tvTitle.setText(result.get(NAME));
            }


        }
    });

But this solution does not work. Anybody here tried this before? I would gladly appreciate any help. Thanks in advance!

1 Answers1

1

Try using selector color instead of settings filter as following:

CircularImageView ci = ...;

ci.setSelected(true);
ci.setSelectorColor(highlightColor);
sergej shafarenka
  • 20,071
  • 7
  • 67
  • 86