Set RippleDrawable corner radius programmatically

后端 未结 1 757
情书的邮戳
情书的邮戳 2020-12-20 22:09

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[]

1条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-20 23:02

    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:

    ColorStateList pressedStates = ColorStateList.valueOf(Color.BLUE);
    
    GradientDrawable contentDrawable = new GradientDrawable();
    contentDrawable.setColor(Color.WHITE);
    contentDrawable.setCornerRadius(16);
    
    RippleDrawable rippleDrawable = new RippleDrawable(pressedStates, contentDrawable, null);
    container.setBackground(rippleDrawable);
    

    0 讨论(0)
提交回复
热议问题