With the new Theme.MaterialComponents
theme you can define the materialButtonStyle
attribute in your app theme, to customize globally the style of all buttons in your app.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<!-- .... -->
<item name="materialButtonStyle">@style/Widget.App.Button</item>
</style>
With
<style name="Widget.App.Button" parent="Widget.Material3.Button">
<!-- button style customization example -->
<item name="materialThemeOverlay">@style/ThemeOverlay.App.Button</item>
<item name="android:textAppearance">@style/TextAppearance.App.Button</item>
<item name="shapeAppearance">@style/ShapeAppearance.App.SmallComponent</item>
</style>
Use Widget.MaterialComponents.Button
as parent if you are using Material2 theme.
If you would like to override only some attributes like colors from the default style use the materialThemeOverlay
attribute.
Something like:
<style name="Widget.App.Button" parent="Widget.Material3.Button">
<item name="materialThemeOverlay">@style/ThemeOverlay.App.Button</item>
</style>
<style name="ThemeOverlay.App.Button">
<!-- 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>