SnackBar style in theme application

I need help. How to change text design in snackbar in styles app? Changing the code does not interest me. I found the following code. But this does not work for me. Why is this? My theme is derived from @ style / Theme.AppCompat.Light.DarkActionBar ". I would really appreciate help.

<style name="TextAppearance.Design.Snackbar.Message" parent="android:TextAppearance"> <item name="android:textSize">10sp</item> <item name="android:textColor">#FEFEFE</item> </style> <style name="TextAppearance.Design.Snackbar.Action" parent="android:TextAppearance"> <item name="android:textSize">16sp</item> <item name="android:textColor">#FEFEFE</item> </style> 
+16
android styles
source share
3 answers

you need this: tools:override="true"

 <resources xmlns:tools="http://schemas.android.com/tools"> <style name="TextAppearance.Design.Snackbar.Message" parent="android:TextAppearance" tools:override="true"> <item name="android:textColor">@color/text</item> <item name="android:textSize">50sp</item> </style> </resources> 
+15
source share

2018 new way:

https://materialdoc.com/components/snackbars-and-toasts/#with-code

// create an instance

 Snackbar snackbar = Snackbar.make(view, text, duration); 

// set the color of the action button

 snackbar.setActionTextColor(getResources().getColor(R.color.indigo)); 

// get a diner view

 View snackbarView = snackbar.getView(); 

// change the text color of the diner

 int snackbarTextId = android.support.design.R.id.snackbar_text; TextView textView = (TextView)snackbarView.findViewById(snackbarTextId); textView.setTextColor(getResources().getColor(R.color.indigo)); 

// change the background of the diner

 snackbarView.setBackgroundColor(Color.MAGENTA); 
+3
source share

I delved into the sources of Snackbar, and this is what I found, the Snackbar background consists of 2 layers: the base and overlay, the colors of which are mixed.

To specify these colors, simply add themes 2 to your options:

colorSurface - background color, default = 0xFFFFFFFF

colorOnSurface - overlay, default = 0xFF000000

Thus, in the default case, we get the color 0xFF333333, which is located in the middle between white and black.

Have fun mixing and styling your Snackbar :)

0
source share

All Articles