Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change action color of snackbar from style

I need the AppTheme.colorAccent to be brown but I need my Snackbar action color to be blue. How to change action button color of Snackbar from style without changing AppTheme.colorAccent?

I've try this code but it does not work :

<style name="TextAppearance.Design.Snackbar" parent="android:TextAppearance" tools:override="true">
    <item name="colorAccent">#3097ff</item>
</style>
like image 222
zihadrizkyef Avatar asked Sep 19 '25 06:09

zihadrizkyef


1 Answers

With the Material Components Library you can do it.

Just add the snackbarButtonStyle attribute in your theme app.

<style name="AppTheme" parent="Theme.MaterialComponents.*">
    <!-- Style to use for action button within a Snackbar in this theme. -->
    <item name="snackbarButtonStyle">@style/snackbar_button</item>
    ...
</style>

Then define your custom style:

  <style name="snackbar_button" parent="@style/Widget.MaterialComponents.Button.TextButton.Snackbar">
      <item name="backgroundTint">@color/secondaryLightColor</item>
      <item name="android:textColor">@color/primaryDarkColor</item>
  </style>

enter image description here

It requires the version 1.1.0 of the library.

like image 117
Gabriele Mariotti Avatar answered Sep 23 '25 11:09

Gabriele Mariotti