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

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

    The only way I see is using getView() and cycling through its child. I don't know if it's going to work, and it is bad as it looks. I hope they'll add some API about this issue soon.

    Snackbar snack = Snackbar.make(...);
    ViewGroup group = (ViewGroup) snack.getView();
    for (int i = 0; i < group.getChildCount(); i++) {
        View v = group.getChildAt(i);
        if (v instanceof TextView) {
            TextView t = (TextView) v;
            t.setTextColor(...)
        }
    }
    snack.show();
    

提交回复
热议问题