Creating/Editing VectorDrawable in Code

Nathan Sokalski 4,056 Reputation points

I have a VectorDrawable that I need to edit during runtime. I know how to create a VectorDrawable Resource using xml, but I need to edit the pathData of the path element during runtime. I am having trouble finding the documentation on & how to edit the different components of a VectorDrawable in codebehind. Any ideas?

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,006 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 47,896 Reputation points Microsoft Vendor


    Welcome to our Microsoft Q&A platform!

    If you xml file put in the Assets folder, you can use this way to edit the xml at the runtime,

       XmlDocument xmlDocument = new XmlDocument();  
                   XmlNodeList tagList = xmlDocument.GetElementsByTagName("path");  
                   foreach (XmlElement xmlElement in tagList)  
                       XmlAttribute name = xmlElement.GetAttributeNode("android:pathData");  
                       name.Value = @"M15.5,14h-0.79l-0.28,-0.27C15.41,12.59";  
                       //if (name.Equals("pathData"))  
                       //    xmlElement.InnerText = @"M15.5,14h-0.79l-0.28,-0.27C15.41,12.59";  

    Best Regards,

    Leon Lu

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful