Skip to content

Instantly share code, notes, and snippets.

@sonnguyen0310
Created January 12, 2021 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sonnguyen0310/cdf952bed402b1615a27af3e65535133 to your computer and use it in GitHub Desktop.
Save sonnguyen0310/cdf952bed402b1615a27af3e65535133 to your computer and use it in GitHub Desktop.
Android Kotlin's extension rounded corner any view
fun View.clipToRounded(curveRadius: Float) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
outlineProvider = object : ViewOutlineProvider() {
override fun getOutline(view: View?, outline: Outline?) {
view?.let {
outline?.setRoundRect(0, 0, it.width, (view.height), curveRadius)
}
}
}
clipToOutline = true
}
}
//Usage
view.clipToRounded(40f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment