Android Material Button Taking Color Primary Instead Of Color Accent
I have my layout button as -
Solution 1:
You can check the official doc.
The filled button has the backgroundTint
based on the colorPrimary
.
Also in your buttonView
style you should extend one of the provided styles:
Default style Widget.MaterialComponents.ButtonIcon style Widget.MaterialComponents.Button.Icon
Unelevated style. Widget.MaterialComponents.Button.UnelevatedButton
Unelevated icon style Widget.MaterialComponents.Button.UnelevatedButton.Icon
Example:
<stylename="buttonView"parent="Widget.MaterialComponents.Button"></style>
If you want to change the background color you can:
Use the
backgroundTint
attribute in your custom styleOverride the
colorPrimary
attribute in your custom style using thematerialThemeOverlay
(best solution)
Example:
<stylename="buttonView"parent="Widget.MaterialComponents.Button"><itemname="materialThemeOverlay">@style/CustomButtonThemeOverlay</item></style><stylename="CustomButtonThemeOverlay"><itemname="colorPrimary">@color/...</item></style>
Solution 2:
For my case this problem comes around when updating android studio to version 4.1.. button background color, always get color primary purple_500 by default. your code does not have problem. I set backgroundTint attribute to null and background attribute to favorite color, or just set backgroundTint to favorite color.
Post a Comment for "Android Material Button Taking Color Primary Instead Of Color Accent"