Android Fresco Load Vector Drawable From Uri

Nov 22, 2019
val iconUri = UriUtil.getUriForResourceId(R.drawable.ic_add_black_24dp)val vectorResourceId = if (iconUri != null && UriUtil.isLocalResourceUri(iconUri)) {    val resourceId = iconUri.pathSegments[0].toInt()    val fileExt = context.resources.getFileExt(resourceId)    if (fileExt == "xml") // probably a vector        resourceId    else        null} else nullif (vectorResourceId != null) {    simpleDraweeView.hierarchy.setPlaceholderImage(vectorResourceId)    // optional    // simpleDraweeView.setImageURI(null as Uri?)    // deprecated    // simpleDraweeView.setImageResource(vectorResourceId)    // use imageView.setImageResource(vectorResourceId)    // this would not work for vector resource    // simpleDraweeView.setActualImageResource(vectorResourceId)} else {    simpleDraweeView.setImageURI(item.iconUri)}

NOTE: Technically, Freso doesn't support vector image.

NOTE: Android Check Resources Id Is Vector

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.