0

So I want to change the shape of a button in android studio. I have tried and followed multiple guides and nothing seems to work. I think I messed something up in some other files such as themes maybe.

I have tried this https://stackoverflow.com/a/18879660/14973568 and https://www.youtube.com/watch?v=plQIpqBcdQE and also This was the last attempt at resolving the problem

code in the picture:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#F4CD47"/>
    <corners android:topRightRadius="120dp"
        android:topLeftRadius="120dp"
        android:bottomLeftRadius="120dp"
        android:bottomRightRadius="120dp" />
</shape>    

but I could only change it with backgroundTint.

rounded_button.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#fff" />
    <corners android:radius="130dp" />
</shape>

activity_game.xml:

<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"
    tools:context=".game"
    android:background="#396dbf">

    <TextView
        android:id="@+id/credit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="16dp"
        android:text="@string/creditText"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <ImageView
        android:id="@+id/backButton"
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/back"
        android:contentDescription="TODO" />

    <ImageView
        android:id="@+id/logo"
        android:layout_width="100dp"
        android:layout_height="85dp"
        android:layout_marginTop="4dp"
        android:layout_marginEnd="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/logo" />

    <Button
        android:id="@+id/button1"
        android:layout_width="276dp"
        android:layout_height="56dp"
        android:layout_marginTop="380dp"
        android:background="@drawable/rounded_button"
        android:backgroundTint="#FFE500"
        android:fontFamily="sans-serif-black"
        android:textColor="#000000"
        android:textSize="14sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.496"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button2"
        android:layout_width="276dp"
        android:layout_height="56dp"
        android:layout_marginTop="40dp"
        android:backgroundTint="#FFE500"
        android:fontFamily="sans-serif-black"
        android:textColor="#000000"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.496"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button1" />

    <Button
        android:id="@+id/button3"
        android:layout_width="276dp"
        android:layout_height="56dp"
        android:layout_marginTop="40dp"
        android:backgroundTint="#FFE500"
        android:fontFamily="sans-serif-black"
        android:textColor="#000000"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.496"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button2" />

    <TextView
        android:id="@+id/question"
        android:layout_width="245dp"
        android:layout_height="173dp"
        android:layout_marginTop="132dp"
        android:layout_marginEnd="80dp"
        android:background="@drawable/whiteback"
        android:text="TextView"
        android:textAlignment="center"
        android:textAllCaps="false"
        android:textColor="#000000"
        android:textSize="18sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
  • 1
    Try with this, https://stackoverflow.com/a/45832238/9701793. If you could give a preview image of what you want then we can help you out. – rahat Jan 09 '21 at 18:33
  • @rahat I tried it but it doesn't work. When I'm creating the button_background.xml file, I can see the changes on the preview to the right, but when I set the background of the button to the @drawable/button_background, nothing changes. I want it to look something like: [button] (https://stackoverflow.com/questions/61054834/how-to-make-buttons-rounded-with-material-design-theming) – Mount Triglav Jan 10 '21 at 19:11
  • Well then please add the xml for the button to the question, – rahat Jan 11 '21 at 04:48
  • @rahat I did, I hope this shows my mistake. – Mount Triglav Jan 11 '21 at 16:28
  • I tried with your code, shape is changing, its rounding the button, specify what you want exactly – rahat Jan 11 '21 at 16:36
  • What I was trying to achieve was to shape the button. I have managed to change its radius by adding app: cornerRadius="120dp" Whenever I tried to apply the methods above, the button would stay in its default shape. – Mount Triglav Jan 13 '21 at 09:30

0 Answers0