安卓字符串颜色

标签 android string colors

是否可以在 Android 中更改字符串中某些字符的颜色?例如,将单词 android 中字母 d 和 r 的颜色更改为绿色。

<TextView
        android:id="@+id/word"
        android:gravity="center_vertical"
        android:typeface="monospace"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        android:textSize="30pt"/>

最佳答案

您可以使用 html 而不是纯文本来初始化 TextView。 html 可以用颜色定义文本范围。参见 Set TextView text from html-formatted string resource in XML如何。

如果你不想使用 html,你可以使用 SpannableString .

关于安卓字符串颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9450981/

相关文章:

android - 更改 Spinner 弹出窗口的背景颜色

colors - 在Mathematica中创建具有不同颜色边缘的图形

javascript - 颜色比例取决于绘制点的频率(JS Canvas)

c# - String、FormattableString、IFormattable 之间的区别

python - 使用Python的regex .match()方法获取下划线前后的字符串

graphics - 在线性与非线性 RGB 空间中处理颜色时有哪些实际区别?

android - 如何获取某一列中具有相同值的行列表?

android - 拥有在我的应用程序包 ID 中使用的域

android - 如何使用 NFC 重定向或打开我的 Progressive Web App?

C::how:运行错误检查循环中的字符串是否太长