Search code examples
androidandroid-vectordrawable

activating and deactivating certain paths in a drawable


I am trying to make a hangman app and have created a hangman SVG file with separate paths for each of the body parts in the vector.

Is there a way to turn these paths on and off so I don't need to make several copies of the file for each stage of the hangman game?


Solution

  • Only one way to do that,

    Use RichPath:

    1- vector_drawable.xml

    <vector >
        <path
            ...
            android:name="path_name"
            ... />
    </vector>
    

    2- In your layout.

    <com.richpath.RichPathView
        ...
        app:vector="@drawable/vector_drawable"
        ... />
    

    3- Find a RichPath.

    RichPath richPath = richPathView.findRichPathByName("path_name");
    

    4- Change any attribute

    richPath.set..();
    

    for example fillColor, strokeColor, strokeAlpha, fillAlpha, trimPathEnd, trimPathOffset and more.

    For more info check the README file.