0

I have created an XML file for giving round shape and gradient color to my button.

In the layout file, inspite of using android:background="@drawable/button_color, white button is appearing.

I need to replace it with my gradient color.

Can someone review my code?

Thanks in advance.

Here is my code:

This is my XML: res>drawable>button_color.xml

<shape
    android:shape = "rectangle"
    xmlns:android = "http://schemas.android.com/apk/res/android" >

    <corners android:radius="25dp" />
    <gradient android:angle="270"
        android:endColor="#36aec6"
        android:startColor="#8cc542" />

</shape>

Layout file:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="100dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="8dp">

            <ImageView
                android:id="@+id/logoImage"
                android:layout_width="50dp"
                android:layout_height="match_parent"
                android:layout_alignParentStart="true"
                android:layout_marginStart="0dp"
                android:src="@drawable/logo"
                android:contentDescription="@string/acuvisor" />

            <ImageView
                android:id="@+id/companyName"
                android:layout_width="170dp"
                android:layout_height="match_parent"
                android:layout_toEndOf="@id/logoImage"
                android:src="@drawable/company_name"
                android:contentDescription="@string/acuvisor" />

            <TextView
                android:id="@+id/Help"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/help"
                android:layout_alignParentEnd="true"
                android:layout_centerInParent="true"
                android:textSize="16sp"
                android:clickable="true"
                android:padding="12dp"
                tools:ignore="RelativeOverlap" />


        </RelativeLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/languageRV"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="8dp"
        android:layout_margin="12dp"/>

    <Button
        android:id="@+id/nextButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:text="@string/next"
        android:textColor="@color/black"
        android:background="@drawable/button_color"/>

</LinearLayout>

Output:

Screen

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • check this [answer](https://stackoverflow.com/questions/64722733/android-background-drawable-not-working-in-button-since-android-studio-4-1) contains what you need – Mostafa Onaizan May 26 '21 at 04:21

1 Answers1

0

Use an AppCompat theme instead of a Material Theme like

Theme.AppCompat.DayNight.DarkActionBar

However, if you still want to use the material button just add an app:backgroundTint="@null" attribute before the line you're setting the gradient background.

Narendra_Nath
  • 4,578
  • 3
  • 13
  • 31