-1

I have followed the guidelines to how to implement Material Components to my app and have assigned the Theme.MaterialComponents.NoActionBarto my AppTheme and in my main activity it has a CoordinatorLayout as mentioned in material.io to best display the Snackbar but i get this result.

enter image description here

Edit: I have tried to change the background color of the Snackbar in style as well as set a textViewStyle but those options didn't work

if more info is needed i will edit and add the missing info.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Mustafa Osta
  • 41
  • 1
  • 8

3 Answers3

2

Use this code :

snackBarView.getView().setBackgrondColor(ContextCompat.getColor(getActivity(),R.color.Blue));
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
jins joseph
  • 271
  • 1
  • 11
0

You can change the text and background color like this.

  Snackbar snackbar = Snackbar
            .make(view, "Hello", Snackbar.LENGTH_SHORT);
    View sbView = snackbar.getView();
    sbView.setBackgroundColor(Color.RED);
    TextView textView = sbView.findViewById(android.support.design.R.id.snackbar_text);
    textView.setTextColor(Color.WHITE);
    textView.setTypeface(FontHelper.getFont(Fonts.MULI_SEMI_BOLD));
    snackbar.show();

Alternate way to change the snackbar background color refer the link

https://stackoverflow.com/a/54484438/7108030

If you have still any doubts share your sample code and if this answer is helpful give positive feedback.

  • this did not solve the problem as it still display the same issue as shown in the image posted in the question – Mustafa Osta May 03 '19 at 07:08
  • You can customize the layout also refer the given link https://stackoverflow.com/a/33441214/7108030 – VinothKumar Subramani May 03 '19 at 07:09
  • adding `textView.setBackgroundColor(Color.parseColor("#323232"));` ("#323232" is the color of the snackbar as color-picked from [material.io](https://material.io/design/components/snackbars.html#spec) would change the background of the `TextView` in Snackbar but I believe the background color should be manipulated in `style.xml` and not programmatically in each call of Snackbar as that would be inefficient – Mustafa Osta May 03 '19 at 07:20
  • Refer the above provided link . – VinothKumar Subramani May 03 '19 at 07:35
  • Only option is you have to set the textview and snack bar color programmatically otherwise it will take by default white color which you mentioned in the style sheet. in your case you have mentioned background color in stylesheet white. so, it will take by default all the background color white only – VinothKumar Subramani May 03 '19 at 07:52
0

I have found the error as there was <item name="android:background">@color/white</item> overriding the TextView background color and even specifying the android:background in the specified style of the widget will not override the main background specified in the main AppTheme

Mustafa Osta
  • 41
  • 1
  • 8