如何在Android textview中定义不同的粗体字体

时间:2013-09-14 10:55:17

标签: android android-fonts

我需要为Android textview中呈现的HTML文本中的粗体元素使用不同的字体。

我尝试这样做,但看起来字体样式参数只是将整个textview设置为普通或粗体,而不是在textview中设置该样式的字体。

TextView tv = (TextView) dialogView.findViewById(R.id.textInstructions);
String instructions = "<b>Headline</b><br/>Regular Text";
tv.setText(Html.fromHtml(instructions));

Typeface font = Typeface.createFromAsset(BaseActivity.this.getAssets(), "OpenSans-Regular.ttf");
Typeface bold = Typeface.createFromAsset(BaseActivity.this.getAssets(), "OpenSans-Bold.ttf");
tv.setTypeface(font, Typeface.NORMAL);
tv.setTypeface(bold, Typeface.BOLD);

看起来这个stackoverflow问题回答了它,它需要一个将两种真正的类型字体合并为一个:

Html in text view with different fonts for bold and italic

但是我无法找到如何在ttfedit中合并字体的说明。我打开了实用程序,但对如何使用它感到很茫然。

2 个答案:

答案 0 :(得分:0)

看起来这个stackoverflow问题回答了它,它需要一个将两种真正的类型字体合并为一个:

Html in text view with different fonts for bold and italic

答案 1 :(得分:0)

tv.setText(Html.fromHtml("<html><body><font size=5 color=red>Hello </font> World </body><html>"));

试试这个。

相关问题