So while fiddling around in Android Studio I came with the question: 'How do you make the corners of the button square?. Looking around the internet and stack overflow I got many answers, but I wondered if there was a much simpler way... and then poof! Under Common attributes in XML design, I saw background, curious I put in '@android:color/white' inside, and then the rounded square button became a 90-degree square button.
This was a nice surprise. Since I didn't see anyone talk about doing this I decided to post here. Hope it was helpful and a quick hack to having 90-degree corners on your buttons!

Code difference Back(with background) and home(no background)
<Button
android:id="@+id/back"
android:background="@color/white"
android:text="Back"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.008" />
<Button
android:id="@+id/home"
android:text="Home"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.007" />

To achieve a square button just use the attribute app:cornerRadius="0dp":
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BUTTON"
app:cornerRadius="0dp"/>
Just note that if you are using a Material Components Theme the Button is replaced at runtime by a MaterialButton.

Note about the android:background="@color/white".
Using the android:background attribute the MaterialButton doesn't use its own MaterialShapeDrawable for the background. This means that features like shape appearance, stroke and rounded corners are ignored.
It is the reason because you are obtaining a square button.
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