我需要用不同颜色的字符串突出显示一些单词。然后将字符串分配给textview的text属性。我没有找到一个简单有效的方法来做这件事。你能帮助我吗?谢谢您。马多克斯
最佳答案
textview.SetTextColor(Color.ParseColor("#787887"));
string character="Helloworld Developer";
string withoutspecialcharacter="Helloworld";
SpannableString spannable = new SpannableString(character);
spannable.SetSpan(new ForegroundColorSpan(Color.Red), character.IndexOf(withoutspecialcharacter), (character.IndexOf(withoutspecialcharacter)) + (withoutspecialcharacter.Length), SpanTypes.ExclusiveExclusive);
textview.TextFormatted = spannable ;