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

前端 未结 22 2356
温柔的废话
温柔的废话 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:58

    This is what I use when I need custom colors

        @NonNull
        public static Snackbar makeSnackbar(@NonNull View layout, @NonNull CharSequence  text, int duration, int backgroundColor, int textColor/*, int actionTextColor*/){
            Snackbar snackBarView = Snackbar.make(layout, text, duration);
            snackBarView.getView().setBackgroundColor(backgroundColor);
            //snackBarView.setActionTextColor(actionTextColor);
            TextView tv = (TextView) snackBarView.getView().findViewById(android.support.design.R.id.snackbar_text);
            tv.setTextColor(textColor);
            return snackBarView;
        }
    

    And consumed as:

    CustomView.makeSnackbar(view, "Hello", Snackbar.LENGTH_LONG, Color.YELLOW,Color.CYAN).setAction("DO IT", myAction).show();
    

提交回复
热议问题