1

I am trying to give my button a gradient background and stronger stroke. I have read/seen many tutorials but nothing works for me.

This is my addon .xml file

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:shape="rectangle">

    <gradient android:startColor="#25AAFF"
        android:endColor="#004F81">
    </gradient>

    <stroke
        android:width="5dp"
        android:color="#000000">
    </stroke>

    <corners android:radius="5dp"></corners>

NOTE: The corners work fine

and Button file

     <Button
        android:background="@drawable/login_button"
        android:id="@+id/login_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/login_password_input"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="@string/login_button_text"
        android:textColor="#FFFFFF"
        android:textStyle="bold">
    </Button>

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
goolek2d
  • 11
  • 1

1 Answers1

0

Using the Material Components Library there is no difference between <Button /> and <com.google.android.material.button.MaterialButton />. Check this post for more info.

MaterialButton ignored android:background until release 1.2.0-alpha06. With this release you can have a gradient background using something like:

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

Also you can apply the stroke using the app:cornerRadius, app:strokeWidth and app:strokeColor attributes:

<Button
    app:cornerRadius="4dp"
    app:strokeWidth="1dp"
    app:strokeColor="@color/primaryLightColor"
    ..>

If you are using an earlier versions of the material components library you can use the AppCompatButton:

<androidx.appcompat.widget.AppCompatButton
    android:background="@drawable/bg_button_gradient"
    ..>
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841