How to set support library snackbar text color to something other than android:textColor?
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))
I know this has been answered already but the easiest way I found was directly in the make using the Html.fromHtml
method and a font
tag
Snackbar.make(view,
Html.fromHtml("<font color=\"#ffffff\">Tap to open</font>").show()
Alright so I fixed it by basically reorganizing the way I do text colors.
In my light theme, I set android:textColorPrimary
to the normal dark text
I wanted, and I set android:textColor
to white
.
I updated all of my text views and buttons to have android:textColor="?android:attr/textColorPrimary".
So because snackbar draws from textColor
, I just set all of my other text to textColorPrimary
.
EDIT JANUARY 2017: ----------------------------------------------------
So as the comments say, and as stated in the edited original question above, you should probably not define android:textColor
in your themes, as this changes the text color of every view inside the theme.