我需要用不同的颜色突出显示字符串中的一些单词。然后该字符串将分配给 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 ;
关于c# - Xamarin C# 安卓 : change color text in a substring?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44258241/