Android: Rounded buttons
24th May 2021
People writing HTML take it for granted how easy it is for them to make a rounded button. Just slap a
border-radius-10px
on a div and hey presto, child-safe button.
In Android we need to make a separate XML file and then use that as the background for our button. 9 lines of code for some rounded corners.
Roundy xml
Activity xml
Result
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#EEAF5252" />
<corners android:bottomRightRadius="50dp"
android:bottomLeftRadius="50dp"
android:topRightRadius="50dp"
android:topLeftRadius="50dp"/>
</shape>
<androidx.appcompat.widget.AppCompatButton
...
android:background="@drawable/rounded_button"/>