1

This is how the button looks right now:

Current Button

android:background= "@color/white" does not change anything.

Code:

 <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="20dp"
            android:text="Button"
            android:background="@color/white"/>
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841

3 Answers3

1

Use app:backgroundTint="#FFFFFF"

If you want to use a selector, you will need to have android:background="@drawable/your_button_selector_id" as the button background for the selector to work.

Selector:

   <selector xmlns:android="schemas.android.com/apk/res/android">

   <item android:drawable="@color/white" android:state_selected="true" />

 <item android:drawable="@color/black" android:state_selected="false" /> </selector>
happyvirus
  • 279
  • 3
  • 21
1

Since you are using a color just use the app:backgroundTint attribute:

<Button
    app:backgroundTint="@color/white"/>

If you just need rounded corners with a stroke, you don't need a drawable.

For it use:

    <com.google.android.material.button.MaterialButton
        app:cornerRadius="16dp"
        app:backgroundTint="@color/white"
        app:strokeColor="@color/black"
        android:textColor="@color/black"
        app:strokeWidth="2dp" />

enter image description here

happyvirus
  • 279
  • 3
  • 21
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
0

Did you add value for white in your colors.xml? if not open colors.xml and add

<color name="white">#FFFFFF</color>

Full Explanation here https://stackoverflow.com/a/2749027/7174681

Biscuit
  • 4,840
  • 4
  • 26
  • 54
IUN KHAN
  • 30
  • 1
  • 7