【问题标题】:How to apply color for specific number in given string android? [duplicate]如何为给定字符串android中的特定数字应用颜色? [复制]
【发布时间】:2017-12-11 05:53:14
【问题描述】:

我从响应中得到一个数字,我将它附加在 TextView 中。现在我需要更改在colors.xml 中声明的特定数字的颜色。但我不知道如何通过应用颜色来单独更改特定数字。

例如:文本颜色为黑色,数字颜色为蓝色。

 retailerCount.setText("Performance of "+seProfile.getTotRetailerCnt()+ " retailers in Route Plan");
//retailerCount.setTextColor(getColor(R.color.colorAccent));//this applies entirely.

seProfile.getTotRetailerCnt 将数字显示为响应中的 15。

因此输出将是路线计划中 15 家零售商的绩效。 所以在这里,我需要为 15 应用蓝色,为其他文本应用黑色。

【问题讨论】:

    标签: android textview spannablestring


    【解决方案1】:

    试试这个:

    retailerCount.setText(Html.fromHtml("<font color=\"#000000\">" +"Performance of "+ "</font>" + "<font color=\"#0000FF\">" +seProfile.getTotRetailerCnt() + "</font>"+"<font color=\"#000000\">"+" retailers in Route Plan"+"</font>"));
    

    我可能会错过字体打开或关闭运行检查它

    【讨论】:

      猜你喜欢
      • 2016-09-19
      • 2014-06-19
      • 2014-09-28
      • 2017-03-27
      • 1970-01-01
      • 1970-01-01
      • 2019-03-15
      • 1970-01-01
      • 2021-02-11
      相关资源
      最近更新 更多