Search code examples
androidmaterial-designandroid-buttonmaterial-components-androidandroid-imagebutton

Can android:buttonStyle and android:imageButtonStyle be used for Theme.MaterialComponents?


For Theme.AppCompat, one can use android:buttonStyle and android:imageButtonStyle to style Button and ImageButton respectively for all activities. They do not seem to work for Theme.MaterialComponents. If not, what is the equivalent for Theme.MaterialComponents? Could anyone shed some light on this?

The old theme example:

<style name="OnviferThemeStyle" parent="Theme.AppCompat">
     ...   

    <item name="android:buttonStyle">@style/fooButton</item>
    <item name="buttonStyle">@style/fooButton</item>
    <item name="android:imageButtonStyle">@style/fooImageButton</item>
    <item name="imageButtonStyle">@style/fooImageButton</item>

</style>

Solution

  • With the MaterialComponents theme you can use the materialButtonStyle attribute.

    <style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
       <item name="materialButtonStyle">@style/....</item>
    </style>
    

    For the ImageButton currently there isn't a Material Components. You can still use the ImageButton component and the imageButtonStyle attribute.