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

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

    I found this at What are the new features of Android Design Support Library and how to use its Snackbar?

    This worked for me for changing the text color in a Snackbar.

    Snackbar snack = Snackbar.make(view, R.string.message, Snackbar.LENGTH_LONG);
    View view = snack.getView();
    TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
    tv.setTextColor(Color.WHITE);
    snack.show();
    



    UPDATE: ANDROIDX: As dblackker points out in the comments, with the new AndroidX support library, code to find the ID of Snackbar TextView changes to:

    TextView tv = view.findViewById(com.google.android.material.R.id.snackbar_text);
    tv.setTextColor(ContextCompat.getColor(requireContext(), R.color.someColor))
    

提交回复
热议问题