Created
January 12, 2021 01:13
-
-
Save sonnguyen0310/cdf952bed402b1615a27af3e65535133 to your computer and use it in GitHub Desktop.
Android Kotlin's extension rounded corner any view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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