如何更改 TextView 一部分的颜色? [英] How can I change the color of a part of a TextView?
本文介绍了如何更改 TextView 一部分的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
text = text + CepVizyon.getPhoneCode() + "
"
+ getText(R.string.currentversion) + CepVizyon.getLicenseText();
activationText.setText(text);
myTextView.setText(text);
我想更改 CepVizyon.getPhoneCode()
字符串的颜色.我该怎么做?
I want to change color for CepVizyon.getPhoneCode()
's string. How can I do this?
推荐答案
Spannable 更多灵活:
String text2 = text + CepVizyon.getPhoneCode() + "
"
+ getText(R.string.currentversion) + CepVizyon.getLicenseText();
Spannable spannable = new SpannableString(text2);
spannable.setSpan(new ForegroundColorSpan(Color.WHITE), text.length(), (text + CepVizyon.getPhoneCode()).length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
myTextView.setText(spannable, TextView.BufferType.SPANNABLE);
这篇关于如何更改 TextView 一部分的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文