With the new Theme.MaterialComponents
theme you can define the materialButtonStyle
attribute in your app theme.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
....
<item name="materialButtonStyle">@style/MyButtonTheme</item>
</style>
In this way you can customize globally the style of all buttons in your app.
You can override the theme attributes from the default style using the materialThemeOverlay
attribute.
Something like:
<style name="MyButtonTheme" parent="Widget.MaterialComponents.Button">
<item name="materialThemeOverlay">@style/ButtonStyleTextColor</item>
</style>
<style name="ButtonStyleTextColor">
<!-- For filled buttons, your theme's colorPrimary provides the default background color of the component, and -->
<!--the text color is colorOnPrimary -->
<item name="colorPrimary">@color/my_color</item>
<item name="colorOnPrimary">@color/my_color2</item>
</style>
Currently the materialThemeOverlay
attribute requires version 1.1.0 of material components for android library.