0

I have tried copying several different examples, used shape layouts, tried images, etc. No matter what I do, it is a though the the background drawable is simply ignored. I intentionally put an error into the drawable xml to be sure it was being seen, that triggered an error. I have my drawable stuff in res/drawable.

Any ideas?

<Button android:id="@+id/buttonClose"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Test"`enter code here`
    android:padding="5dip"
    android:layout_gravity="center"
    android:layout_alignParentBottom="true"
    android:onClick="closeScoreBoard"
    android:background="@drawable/button_close"
    />


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

    <solid   android:color="#FF0000"/>

    <corners
        android:bottomRightRadius="8dip"
        android:bottomLeftRadius="8dip"
        android:topLeftRadius="8dip"
        android:topRightRadius="8dip"
/>
</shape>
TomZ
  • 7
  • 2
  • 6

3 Answers3

3

Just use

<androidx.appcompat.widget.AppCompatButton 

It helped me.

1

After searched everywhere, I got this solution and it's working fine. Go to values > theme

  1. Change the parent theme from Theme.MaterialComponents.DayNight.DarkActionBar to "Theme.AppCompat.DayNight.DarkActionBar"

  2. Paste this before ""

<stylename="Material.Theme"parent="Theme.MaterialComponents.DayNight.DarkActionBar">

UTTAM
  • 319
  • 3
  • 4
0

Changing background is not ignored. Simply background is not visible because of the foreground drawable. You may find more info here: Standard Android Button with a different color

or ready to use sample here: http://ogrelab.ikratko.com/custom-color-buttons-for-android/

Community
  • 1
  • 1
Ognyan
  • 13,452
  • 5
  • 64
  • 82