c# - Xamarin.Android 上的多个彩色 Activity 标签元素

标签 c# android mobile xamarin xamarin.android

我想知道是否可以让 Label 元素由两种不同的颜色组成。例如,我的标签是“MyLabel”,我希望“我的”部分为红色,“标签”部分为蓝色。

我尝试使用本指南,但这种方法仅适用于一种颜色。 https://blog.qualtechsoftware.com/how-to-customize-the-title-android-with-xamarin

最佳答案

查看 Android 文档中的SpannableString

http://developer.android.com/reference/android/text/SpannableString.html

    var textView = FindViewById<TextView>(Resource.Id.my_label);
    var span = new SpannableString("My Label");

    span.SetSpan(new ForegroundColorSpan(Color.Red), 0, 2, 0);  // "My" is red
    span.SetSpan(new ForegroundColorSpan(Color.Blue), 3, 8, 0); // "Label" is blue
    textView.SetText(span, TextView.BufferType.Spannable);

关于c# - Xamarin.Android 上的多个彩色 Activity 标签元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26998122/

相关文章:

c# - 如何从单个解决方案生成多个 .exe 文件?

android - 顶部的上下文菜单

c# - 如何让一些碰撞器忽略 Unity 3D 中的触发器

android - 为什么嵌套权重对性能不利?备择方案?

android - 可以像这样将参数传递给 fragment 吗?

css - 在智能手机上导航返回时不会触发媒体查询

android - 如何计算 flurry 移动应用用户的平均 "kill score"

javascript - 他们的任何带有幻灯片的响应式灯箱是否具有适当的滑动?

c# - 委托(delegate)类型和事件处理程序类型有什么区别?

c# - 从 DataGridCell 获取控件