Material components not using color accent declared in theme

Viewed 3868

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.

5 Answers

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. :)

Inherit your app theme from Theme.AppCompat like:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    ...
</style>

Note that dark or light theme is upon you but you need to extend Theme.AppCompat.

Related