How to change background color of the snackbar?

后端 未结 16 737
温柔的废话
温柔的废话 2020-12-07 19:28

I am showing snackbar in DialogFragment Within the Positive click of alertDialog. Here is my code snippet.

Snackbar snackbar = Snackbar.make(view, \"Please e         


        
16条回答
  •  离开以前
    2020-12-07 20:14

    Put it in an Utility class:

    public class Utility {
        public static void showSnackBar(Context context, View view, String text) {
            Snackbar sb = Snackbar.make(view, text, Snackbar.LENGTH_SHORT);
            sb.getView().setBackgroundColor(ContextCompat.getColor(context, R.color.colorAccent));
            sb.show();
        }
    }
    

    Using like this:

    Utility.showSnackBar(getApplicationContext(), findViewById(android.R.id.content), "Add success!!!");
    

提交回复
热议问题