androidiconspngandroid-drawable

Change png icon color in from drawable resources


I have a png icon in drawable. It's black with the transparent background.

How can I change the icon color without adding another drawable?


Solution

  • You can use a ColorFilter to change the icons color at runtime.

    Try something like this:

        Drawable mIcon= ContextCompat.getDrawable(getActivity(), R.drawable.your_icon);
        mIcon.setColorFilter(ContextCompat.getColor(getActivity(), R.color.new_color), PorterDuff.Mode.MULTIPLY);
        mImageView.setImageDrawable(mIcon);