How to set support library snackbar text color to something other than android:textColor?

前端 未结 22 2361
温柔的废话
温柔的废话 2021-01-30 12:33

So I\'ve started using the new Snackbar in the Design Support Library, but I found that when you define \"android:textColor\" in your theme, it applies to the text color of the

22条回答
  •  野的像风
    2021-01-30 12:41

    Just to save your precious development time, here is the static method I am using:

    public static void snack(View view, String message) {
        if (!TextUtils.isEmpty(message)) {
            Snackbar snackbar = Snackbar.make(view, message, Snackbar.LENGTH_SHORT);
            snackbar.getView().setBackgroundColor(Color.YELLOW);
            TextView tv =  snackbar.getView().findViewById(android.support.design.R.id.snackbar_text); //snackbar_text
            tv.setTextColor(Color.BLACK);
            snackbar.show();
        }
    }
    

    This is how it looks:

提交回复
热议问题