Vector drawables in XML, even with support 23.3.0. Guess how?
You've probably heard that the latest support library release today removed some support for backward-compatible inflation of vector drawables
.¹ 😭 You can still use app:srcCompat="@drawable/vector"
, but android:src
won't work and neither will android:drawableLeft
(and so on).
However, if you use data binding, this isn't a huge deal
. Overloading android:
XML attributes has been one of the perks of data binding from the start!² I've posted a gist showing how to inflate and set vector drawables using the same XML attributes you were using before. https://gist.github.com/lisawray/78c33f76809d2bcbbec9983e2c141a70
1) You must inflate your layout using data binding
2) Import R
in the <data></data>
block and reference your vector drawable like R.drawable.vector
instead of @drawable/vector
3) For non-vector drawables, simply don't use data binding, e.g. android:src="@drawable/png"