c# - Xamarin C# 安卓 : change color text in a substring?

标签 c# android xamarin colors substring

我需要用不同的颜色突出显示字符串中的一些单词。然后该字符串将分配给 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/

相关文章:

c# - 在 iframe 中打开 pdf

c# - 如何将类对象转换为列表?

Android - 如何通过 Intent 在另一个应用程序中打开文件?

ios - Xamarin.iOS 中的自定义 SQLite 函数

C# WPF窗口背景

java - 如何从文件中读取/写入对象数组列表的数组列表?

android - 如何使用 Android 的 java 在 LinearLayout 上设置 marginTop?

ios - 当链接器配置为链接所有时,Autofac Build() 在最新的 Xamarin iOS 上抛出异常

Xamarin,等待异步函数结束

C# 正则表达式模式获取单词