Thanks to shadowsheep I wrote these styles with Material Components
. I also removed margins. You can compile his app to research Snackbar
.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!-- Snackbar -->
<item name="snackbarStyle">@style/MaterialSnackbarTheme</item>
<item name="snackbarButtonStyle">@style/MaterialSnackbarTextButtonTheme</item>
<item name="snackbarTextViewStyle">@style/MaterialSnackbarTextViewTheme</item>
</style>
<style name="MaterialSnackbarTheme" parent="@style/Widget.MaterialComponents.Snackbar">
<!-- <item name="backgroundTint">#00cc77</item>-->
<!-- <item name="android:background">@drawable/snackbar_background</item>-->
<item name="android:background">#00cc77</item>
<item name="cornerRadius">0dp</item>
<item name="android:layout_margin">0dp</item>
<item name="actionTextColorAlpha">1.0</item>
</style>
<style name="MaterialSnackbarTextButtonTheme" parent="@style/Widget.MaterialComponents.Button.TextButton.Snackbar">
<item name="backgroundTint">#7777ff</item>
<item name="android:textColor">#ffffff</item>
</style>
<style name="MaterialSnackbarTextViewTheme" parent="@style/Widget.MaterialComponents.Snackbar.TextView">
<item name="android:textColor">#ffffff</item>
<item name="android:alpha">1.0</item>
</style>
Where drawable/snackbar_background.xml is:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<solid android:color="#00cc77" />
</shape>
Don't forget to remove from Snackbar.make()
, if you have added:
view.setBackgroundColor(ContextCompat.getColor(context, R.color.bg_color))
setActionTextColor(ContextCompat.getColor(context, R.color.button_color))
Unlike AlertDialog
, Snackbar
holds snackbarButtonStyle
and snackbarTextViewStyle
settings inside AppTheme
(that's strange because yesterday they worked well inside MaterialSnackbarTheme
).
As @StayCool said in comments, Snackbar
currently uses transparency for background and text color (alpha = 0.5 - 0.6). Also they added round corners and margins. To remove background transparency, use either <item name="actionTextColorAlpha">1.0</item>
or drawable/snackbar_background.xml. You can see his variant.
