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

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

    Hacking on android.support.design.R.id.snackbar_text is fragile, a better or less hacky way to do that will be:

    String snackText = getResources().getString(YOUR_RESOURCE_ID);
    SpannableStringBuilder ssb = new SpannableStringBuilder()
        .append(snackText);
    ssb.setSpan(
        new ForegroundColorSpan(Color.WHITE),
        0,
        snackText.length(),
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    Snackbar.make(
            getView(),
            ssb,
            Snackbar.LENGTH_SHORT)
            .show();
    

提交回复
热议问题