android:background="@drawable/XXXX is ignored for a button in main.xml
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开发者_JS百科 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>
Just use
<androidx.appcompat.widget.AppCompatButton
It helped me.
After searched everywhere, I got this solution and it's working fine. Go to values > theme
Change the parent theme from Theme.MaterialComponents.DayNight.DarkActionBar to "Theme.AppCompat.DayNight.DarkActionBar"
Paste this before ""
<stylename="Material.Theme"parent="Theme.MaterialComponents.DayNight.DarkActionBar">
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/
精彩评论