It matters (unless your minSdkVersion
is Q or higher) because theOutline
API explicitly only accepts convex paths — see the documentation. When running on P or lower, you can only pass a Path
for which the isConvex
property is true; if it’s false you’ll get an error (or no outline -> no shadow; I don’t recall). Starting from Q, you can also pass a concave path, but it’s unrealistic as of today to assume you can always do that given the minuscule fraction of users on Q.
In any case, you need to construct a Path
that matches the vector drawable’s outline you want the shadow for, and pass it to the ViewOutlineProvider
for your view. Some pseudo-code:
private fun setOutlineForDrawable() {
val myImageView: ImageView = // ...
val myVectorDrawable = myImageView.drawable val outlinePath: Path = // ... You need to figure how to create
// this by yourself, I can't help with it
val outlineProvider = PathOutlineProvider(outlinePath) myImageView.setOutlineProvider(outlineProvider)
}private class NarrowerOutlineProvider(
private val path: Path
) : ViewOutlineProvider() { override fun getOutline(view: View, outline: Outline) {
// Optional: transform path to adapt to view bounds
outline.setConvexPath(path)
}
}