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.

3 Answers

0
Vinoth Kumar On

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.

2
jins joseph On

Use this code :

snackBarView.getView().setBackgrondColor(ContextCompat.getColor(getActivity(),R.color.Blue));
0
Mustafa Osta On

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