カスタムフォントを太字で表示するのに少し問題があります。これが私がやろうとしていることです。
res / stringにHTML形式の文字列を設定しました
<string name="string1">
<![CDATA[<b>Title1</b><p>sub text</p>]]>
</string>
次に、実行時にフォントを設定します(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);
問題は、テキストが本来あるべき場所に太字で表示されないことです。私が間違っているアイデアはありますか?
申し訳ありませんが、太字のテキストとそうでないテキストが必要であることを追加するのを忘れました。
使用する:
body.setTypeface(tf, Typeface.BOLD);
また、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>
およびロードを使用して:
webView.loadDataWithBaseURL("file:///android_asset/", result, "text/html", "UTF-8", "null");
//編集された質問の場合
String s = getResources().getString(R.string.string1);
((TextView) findViewById(R.id.t)).setText(Html.fromHtml(s), TextView.BufferType.SPANNABLE);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加