The Android Studio 4.1 new-project wizard, for many of its templates, has the project use the Material Components for Android library. And, it sets up the default theme to be based on Theme.MaterialComponents.DayNight.DarkActionBar
.
A side effect of this is that any <Button>
elements in a layout get turned into MaterialButton
widgets, not regular Button
widgets. MaterialButton
ignores android:background
.
If all you want to do is to change the color, use android:backgroundTint
or change the colorPrimary
attribute in the theme.
If you want a button that has a custom background, and your theme is set up to use Theme.MaterialComponents
, you could switch the XML element in the layout to be <android.widget.Button>
instead of <Button>
. This should cause the Material Components for Android to ignore that element, and you can manipulate this button normally with respect to XML attributes.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…