我正在尝试使用@string在TextView中显示一些文本,问题是我似乎无法更改部分文本的颜色。我不想像其他所有问题一样使用Java来执行此操作,因为这是默认的TextView文本。
我试过使用<string name="myString"><font color="#00ff00">My String</font></string>,font fgcolor="#00ff00"但它们似乎没有用。
<string name="myString"><font color="#00ff00">My String</font></string>
font fgcolor="#00ff00"
查看更多
我已经尝试过使用您给定的字符串,它对我来说很有效。这是一个例子
<TextView>在任何布局内创建
<TextView>
<TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/text" />
text在strings.xml文件内创建字符串
text
strings.xml
<string name="text"><font color="#00ff00">Hello</font> <font color="#FF0000">World</font></string>
你可以看到结果
<TextView android:id="@+id/resultTextView" android:text="@string/reusltDefText" android:textAlignment="viewStart" android:textColor="#000000" android:textSize="12sp" android:textStyle="bold" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toStartOf="@+id/divider" app:layout_constraintStart_toStartOf="parent" />
字符串如下所示:`<string name =“ reusltDefText”> <font color =“#ff0000”>我的String!</ font> </ string>`我想到了!这是我的愚蠢错误。谢谢,对不起
@kriskotooBG总是很乐意提供帮助。:)