Skip to content Skip to sidebar Skip to footer

Set Rippledrawable Corner Radius Programmatically

I create a RippleDrawable like below. But I can't change the corner radius of the RippleDrawable. It doesn't have a method like setCornerRadii(float[] f). public static RippleDraw

Solution 1:

I was facing the same issue as you: how to set a corner radius to a RippleDrawable.

A simple manner to proceed is to use a GradientDrawable. You can set a radius with setCornerRadius and then pass the configured instance as the second parameter of the RippleDrawable constructor.

Here is an example:

ColorStateListpressedStates= ColorStateList.valueOf(Color.BLUE);

GradientDrawablecontentDrawable=newGradientDrawable();
contentDrawable.setColor(Color.WHITE);
contentDrawable.setCornerRadius(16);

RippleDrawablerippleDrawable=newRippleDrawable(pressedStates, contentDrawable, null);
container.setBackground(rippleDrawable);

Post a Comment for "Set Rippledrawable Corner Radius Programmatically"