Maaz Hasnain
Maaz Hasnain

Reputation: 53

Button color not changing

I designed a button, this is how it should be but this is how it is. The design changes but the color and border does not.

My fragment file in which I am using the button is:

<?xml version="1.0" encoding="utf-8"?>

<androidx.core.widget.NestedScrollView 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">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".HomeFragment">


        <Button
            android:id="@+id/button_goToOt"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:text="OT Room Lights"
            android:background="@drawable/button_design"
            android:shadowColor="#A8A8A8"
            android:shadowDx="0"
            android:shadowDy="0"
            android:shadowRadius="5"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/OTText" />

        <TextView
            android:id="@+id/OTText"
            android:layout_width="0dp"
            android:layout_height="47dp"
            android:layout_marginTop="16dp"
            android:gravity="center_horizontal"
            android:text="Main Menu"
            android:textAlignment="center"
            android:textAppearance="@style/TextAppearance.AppCompat.Display1"
            android:textColor="@color/material_on_background_emphasis_high_type"
            android:textStyle="bold"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Button
            android:id="@+id/button_goToSurgical"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:text="Surgical Lights"
            android:background="@drawable/button_design"
            android:shadowColor="#A8A8A8"
            android:shadowDx="0"
            android:shadowDy="0"
            android:shadowRadius="5"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/button_goToOt" />

        <Button
            android:id="@+id/button_goToLaminar"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:layout_marginBottom="16dp"
            android:text="Laminar Airflow"
            android:background="@drawable/button_design"
            android:shadowColor="#A8A8A8"
            android:shadowDx="0"
            android:shadowDy="0"
            android:shadowRadius="5"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/button_goToSurgical" />


    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.core.widget.NestedScrollView>

The button_design.xml is

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <corners
        android:topLeftRadius="100dp"
        android:topRightRadius="0dp"
        android:bottomLeftRadius="0dp"
        android:bottomRightRadius="100dp"
        />
    <gradient
        android:angle="45"
        android:centerX="35%"
        android:centerColor="#00A2A8"
        android:startColor="#E8E8E8"
        android:endColor="#000000"
        android:type="linear"
        />
    <padding
        android:left="0dp"
        android:top="0dp"
        android:right="0dp"
        android:bottom="0dp"
        />
    <size
        android:width="270dp"
        android:height="60dp"
        />
    <stroke
        android:width="3dp"
        android:color="#878787"
        />
</shape>

Any help on how to do it? I watched a tutorial in which he just simply changed the background and it worked but it is not working in my case anyone know why?

Upvotes: 1

Views: 49

Answers (1)

Zain
Zain

Reputation: 40810

To avoid taking the default Button style, add app:backgroundTint="@null" to each Button that uses this drawable

This will make sure that the button background doesn't get tinted

enter image description here

Upvotes: 2

Related Questions