Skip to content

Instantly share code, notes, and snippets.

@dextorer
Last active December 24, 2018 12:02
Show Gist options
  • Save dextorer/0af49425900eec37f82f392d52e40d60 to your computer and use it in GitHub Desktop.
Save dextorer/0af49425900eec37f82f392d52e40d60 to your computer and use it in GitHub Desktop.
ripples_pie_regression_2
private fun updateButtonView(button: View) {
val radius = // ...
val color = // ...
val contentOuterRadii = floatArrayOf(radius, radius, radius, radius, radius, radius, radius, radius)
val buttonShape = RoundRectShape(contentOuterRadii, null, null)
if (button.background != null) {
val ripple = button.background as RippleDrawable
(ripple.getDrawable(0) as ShapeDrawable).apply { // content
shape = buttonShape
}
(ripple.getDrawable(1) as ShapeDrawable).apply { // mask
shape = buttonShape
}
} else {
@ColorInt val maskColor = resources.getColor(R.color.white)
val maskShapeDrawable = ShapeDrawable(buttonShape).apply {
paint.color = maskColor
}
val contentShapeDrawable = ShapeDrawable(buttonShape).apply {
paint.color = color
}
button.background = RippleDrawable(ColorStateList.valueOf(maskColor), contentShapeDrawable, maskShapeDrawable)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment