我需要帮助来了解以下问题。
我需要将TextView的单个单词设置为粗体。
我有一个ID为myTextView
的TextView布局:
<TextView
android:id="@+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/open_sans_semi_bold"
android:textColor="#d94256"
android:textSize="20sp" />
我通过编程方式为此视图设置文本:
myTextView.text = HtmlCompat.fromHtml("My fancy string where I want to show this <b>word</b> bold",HtmlCompat.FROM_HTML_MODE_LEGACY)
此外,我尝试使用跨度字符串生成器,但在两种情况下我都得到了the result of this image。
为什么我没有得到类似this的东西?当我更改此行时,我得到以下结果:
android:fontFamily="@font/open_sans_semi_bold"
为此:
android:fontFamily="@font/open_sans_regular"
而且,如果我设置了
android:fontFamily="@font/open_sans_bold"
我可以看到this result
我在Google git存储库中找到了open_sans_semi_bold,open_sans_bold和open_sans_regular的ttf文件。
HTML <b>
标签不是应该像OpenSans Bold一样粗体吗?