1

I have created an xml file called rounded_button.xml for a custom rounded button design that I plan on using in my login screen.

This is the code I have in my xml file

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/colorPrimaryDark"/>
    <corners
        android:topRightRadius="100px"
        android:topLeftRadius="100px"
        android:bottomRightRadius="100px"
        android:bottomLeftRadius="100px"
        />
</shape>

I have tried to implement it in my login screen like this

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    tools:context=".LoginActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Round"
        android:background="@drawable/round_button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

However, the button is still rectangular, and even if I increase the corner sizes, it won't round the edges

  1. What have I done wrong?
  2. Is there a better way to structure my xml file to round the button?
Vennela G
  • 11
  • 3
  • The code looks fine, what if you try `` instead setting the radius of every corner? I would also suggest using dp instead of px – Paula Chittaro Sep 29 '20 at 18:38
  • Thank you! I have applied those changes and it seems like in the **Design** tab on the **round_buttons.xml** file it seems to pick up on the changes but on the actual login screen itself there is no change. Is there some way I can fix that? – Vennela G Sep 29 '20 at 18:42
  • If you want to use a rounded button then you can look into something like this https://stackoverflow.com/a/61055155/5710697. Hope it helps – Sandy Sep 29 '20 at 18:42
  • Thank you Sandy :) – Vennela G Sep 29 '20 at 18:45
  • 1
    Are you using a `MaterialComponents` theme for your app? If so, your ` – Ben P. Sep 29 '20 at 20:33
  • That makes a lot of sense Ben, I was able to fix it. Thank you for the link and the help – Vennela G Sep 29 '20 at 20:53
  • @BenP. Starting from [1.2.0](https://stackoverflow.com/questions/52908045/how-to-set-a-gradient-background-in-a-material-button-from-material-components/61610556#61610556) the `MaterialButton` supports the `android:background` attribute. – Gabriele Mariotti Sep 30 '20 at 13:42
  • @VennelaG In your case you don't need to use a custom background. Just use a `MaterialButton` with the `app:cornerRadius` and `app:backgroundTint` attributes. – Gabriele Mariotti Sep 30 '20 at 13:44

0 Answers0