Search code examples
androidimagevectortogglebutton

How to Invert (Negative) Android Vector Image (Path)


Need area bound by Vector to be transparent and background (Remaining area) to be filled. Required to make it easy to dynamically fill color of vector (Toggle Button Drawable) when the same is bound by a Selector

I Have Vector Path for Below generated from Studio: (Amber space is Transparent)

enter image description here

I want This: (Amber space is Transparent)

enter image description here


Solution

  • Thanks to @pskink - Per his suggestion I used

    myImageView.setColorFilter(Color.WHITE, PorterDuff.Mode.XOR);
    myStateListDrawable.addState(new int[] { android.R.attr.state_checked },  myImageView);
    

    To achieve my needs.

    Scroll down the below link - there are easy to understand examples with other options for ColorFilter

    https://android--examples.blogspot.in/2015/11/android-color-filter-and-different.html