My main app theme parent is MaterialComponents theme. I changed the colors, but material components (MaterialButton, InputLayout, EditText) are not using my accent color (they are using some blue color, my declared Accent color is Teal) What is the issue? How is the best way to deal with theming Material Components?
My main theme:
<style name="AppTheme" parent="Theme.MaterialComponents">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
Edit: Changing theme to Theme.MaterialComponents.Bridge is not solving that problem.
Maybe you should try to use colorSecondary
instead of colorAccent
:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Original AppCompat attributes. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorSecondary">@color/colorAccent</item>
</style>
This works for me
The issue in my case was a different styles.xml
declared for the specific API. I made a mistake in it, and when testing, that other values-v21/styles.xml
was applied before styles.xml
.
So long story short, check if the mistake is not present in other variants. I declared that variant wrong.
For those, trying to use a theme that inherits from Theme.MaterialComponents.*
please also keep in mind not to use a regular Button
class but com.google.android.material.button.MaterialButton
instead.
Instead of:
<Button
(...)
style="@style/Widget.MaterialComponents.Button" />
Make sure to use:
<com.google.android.material.button.MaterialButton
(...)
style="@style/Widget.MaterialComponents.Button" />
Been there. Nothing to be ashamed of. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With