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 write b.setCornerRadius(3.0f), but it is undefined for button object. Thanks.
Use GradientDrawable
GradientDrawable gdDefault = new GradientDrawable();
gdDefault.setColor(bgColor);
gdDefault.setCornerRadius(cornerRadius);
gdDefault.setStroke(strokeWidth, strokeColor);
create a shape in your drawable folder and set the desired radius and set this drawable as background to your button:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="5dip"/>
</shape>
</item>
</layer-list>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With