user1410081
user1410081

Reputation:

Android ImageView's drawable tint not working

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!

Upvotes: 1

Views: 2428

Answers (1)

sergej shafarenka
sergej shafarenka

Reputation: 20416

Try using selector color instead of settings filter as following:

CircularImageView ci = ...;

ci.setSelected(true);
ci.setSelectorColor(highlightColor);

Upvotes: 1

Related Questions