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

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

    One approach is to use spans:

    final ForegroundColorSpan whiteSpan = new ForegroundColorSpan(ContextCompat.getColor(this, android.R.color.white));
    SpannableStringBuilder snackbarText = new SpannableStringBuilder("Hello, I'm white!");
    snackbarText.setSpan(whiteSpan, 0, snackbarText.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    
    Snackbar.make(view, snackbarText, Snackbar.LENGTH_LONG)
                    .show();
    

    With spans you can also add several colors and styles inside one Snackbar. Here's a nice guide:

    https://androidbycode.wordpress.com/2015/06/06/material-design-snackbar-using-the-design-support-library/

提交回复
热议问题