How to set corner radiuses for the button in java code?

前端 未结 4 867
情深已故
情深已故 2020-12-11 05:06

I want to set the rounded corners without xml. How can I do it in java code?

Button b = new Button (this);
b.set???? (??) ;

I tried to wri

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-11 05:33

    Use GradientDrawable

    GradientDrawable gdDefault = new GradientDrawable();
    gdDefault.setColor(bgColor);
    gdDefault.setCornerRadius(cornerRadius);
    gdDefault.setStroke(strokeWidth, strokeColor);
    

提交回复
热议问题