Reputation: 12759
I want to simply apply styling to all buttons on a theme level like this
<style name="BaseTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
...
<item name="buttonStyle">@style/DefaultButton</item>
</style>
<style name="DefaultButton" parent="Widget.MaterialComponents.Button">
<item name="android:textColor">@color/whatever</item>
</style>
<Button
android:id="@+id/addChannelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_margin="16dp"
android:text="Add room" />
Why doesnt this work? It would in appcompat
// If I use Theme.MaterialComponents.Light.NoActionBar.Bridge
, then it works
Upvotes: 3
Views: 3642
Reputation: 365148
Use a Theme.MaterialComponents
theme defining the materialButtonStyle
attribute.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
....
<item name="materialButtonStyle">@style/MyButtonTheme</item>
</style>
In this way you can customize the theme of all the buttons in your app.
Also starting from version 1.1.0 of the material library 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="colorOnPrimary">@color/my_color</item>
</style>
Currently it requires version 1.1.0 of material components for android library.
Upvotes: 2
Reputation: 921
Use materialButtonStyle
and use MaterialButton
instead of Button
Upvotes: 0
Reputation: 38243
Can you try with v1.0.0-alpha06? There has been some progress since v1.0.0 which may have addressed what you're seeing.
Source: https://github.com/material-components/material-components-android/releases
Upvotes: 0
Reputation: 8006
You should be setting materialButtonStyle
instead of buttonStyle
in your theme.
Upvotes: 8