2

Here is my Buttons.xml file

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <corners android:radius="50dp"/>
    <gradient android:startColor="#8E8816"
        android:endColor="#145038"
        android:angle="270" />
    <stroke android:color="#680D0D" android:width="5dp"/>

</shape>

and here is my activity_main.xml i tried to change the android:background as android:src but then also it's not working

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="@color/teal_700"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/buttons"
        android:text="Button" />
</RelativeLayout>

Only the corners attribute is working fine

not only the stroke but also the background is not changing i'm not getting where i'm doing wrong...can anyone help me

here how to button looks like after applying the background as android:background="@drawable/buttons" Button_image

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841

1 Answers1

5

It happens because the Button is replaced with a MaterialButton automatically if your are using a MaterialComponents theme and the default style of the MaterialButton tints the background with the colorPrimary.

You have to use:

<Button
    android:background="@drawable/buttons"
    app:backgroundTint="@null"
    ... />

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841