Android Check Resources Id Is Vector

Nov 23, 2019

Check for xml file extension

val resourceId = R.drawable.ic_check_white_24dpval value = TypedValue()resources.getValue(R.drawable.ic_check_white_24dp, value, true)// value.string = res/drawable/ic_check_white_24dp.xmlval fileExt = value.string.toString().substringAfterLast(".", "")if (fileExt == "xml") {    // probably a vector image}

Use Kotlin Extension

fun Resources.getFileExt(resourceId: Int): String {    val value = TypedValue()    getValue(resourceId, value, true)    return value.string.toString().substringAfterLast(".", "")}
val fileExt = resources.getFileExt(R.drawable.ic_check_white_24dp)

Check Drawable == VectorDrawable

val resourceId = R.drawable.ic_check_white_24dpval d = AppCompatResources.getDrawable(context, resourceId)if (d != null) {    if (d is VectorDrawableCompat || "android.graphics.drawable.VectorDrawable" == d::class.java.name) {        // this is a 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.