Isa*_*aac 5 android android-fonts
我有点麻烦让我的自定义字体显示为粗体,这是我正在尝试做的事情:
我在res/string中设置了一个HTML格式的字符串
<string name="string1">
<![CDATA[<b>Title1</b><p>sub text</p>]]>
</string>
Run Code Online (Sandbox Code Playgroud)
然后我在运行时设置字体(其中getString从字符串中获取resID):
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/eurostileltstddemi.ttf");
TextView body = (TextView) findViewById(R.id.tv_body);
body.setText(Html.fromHtml(getString(name)));
body.setTypeface(tf);
Run Code Online (Sandbox Code Playgroud)
问题是文本没有显示为大胆应该在哪里,任何我想错的想法?
抱歉忘记添加我需要一些粗体文本,有些则不需要.
使用:
body.setTypeface(tf, Typeface.BOLD);
Run Code Online (Sandbox Code Playgroud)
您还可以在 webView 上设置字体。只需添加这样的内容:
<html> <head><style type=\"text/css\"> @font-face { font-family: MyFont; src: url(\"file:///android_asset/font.ttf\") } body { font-family: MyFont; font-size: 12px; text-align: justify; } </style> </head><body>
Run Code Online (Sandbox Code Playgroud)
并使用以下方式加载:
webView.loadDataWithBaseURL("file:///android_asset/", result, "text/html", "UTF-8", "null");
Run Code Online (Sandbox Code Playgroud)
//对于编辑的问题
String s = getResources().getString(R.string.string1);
((TextView) findViewById(R.id.t)).setText(Html.fromHtml(s), TextView.BufferType.SPANNABLE);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5361 次 |
| 最近记录: |