How to change color of vector drawable path on button click

后端 未结 9 1801
北荒
北荒 2020-12-01 00:33

With the new android support update, vector drawables get backward compatibility. I have a vector image with various paths. I want the color of the paths to change on click

9条回答
  •  感动是毒
    2020-12-01 01:25

    You can use this method to change color in lower API to change vector color in fragment

    int myVectorColor = ContextCompat.getColor(getActivity(), R.color.colorBlack);
                        myButton.getIcon().setColorFilter(myVectorColor, PorterDuff.Mode.SRC_IN);
    

    in place of getActivity you should use MainActivity.this for changing vector color in activity

提交回复
热议问题