Getting Android vector drawable as Path

val vectorDrawable = ResourcesCompat.getDrawable(resources, R.drawable.icon, null)  vectorDrawable?.setBounds(0, 0, 800, 800) vectorDrawable?.draw(canvas)

Understanding XML path data

android:pathData="M17.6,9.48l1.84,-3.18c0.16,-0.31 0.04,-0.69 -0.26,..."/>
path.moveTo(17.6f, 9.48f) path.lineTo(19.44f, 6.3f) path.cubicTo(19.6f, 5.99f, 19.48f, 5.61f, 19.18f, 5.45f)
  • M is translated to moveTo
  • l is translated to lineTo
  • c is translated to cubicTo
  • First argument: 17.6 + 1.84 = 19.44
  • Second argument 9.48 3.18 = 6.3

Generating Path code from vector image using an online generator

Converting vector XML into Path programmatically

  1. Parse content of a vector XML drawable and extract pathData attribute from it
  2. Create new Path object from path data
import  PathParser.createPathFromPathData(pathData)




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

[android-EN] SSLHandshakeException: Handshake failed

[Flutter] CRUD PhpMyAdmin (000webhost) via http request

Architecture Components & MVP \ MVVM

Android Networking in 2019 — Retrofit with Kotlin’s Coroutines

Fetching Models at Runtime with Sceneform and ARCore

Android Custom Seek Bar with Floating Textview

Implementation of SDUI with Flutter

Implementation Mixpanel in Android — Part 1

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


More from Medium

Wireless Debugging — Android Apps

How to Handle Process Death on Android

Canvas Draw : Make a custom views

Simple Android Network Traffic Inspection With Chucker And Seismic

Worms Eye View From Spiral colored decore glass through a roof