0

静的レイアウトのテキストを太字にする方法はありますか? 次のコードを使用して StaticLayout を使用してテキストを設定するように、1 つの政府文書を印刷しようとしていますCanvas

TextPaint mTextPaint=new TextPaint();
mTextPaint.setTypeface(Typeface.createFromAsset(context.getAssets(),"fonts/times.ttf"));

    StaticLayout mTextLayout;
    canvas.save();

mTextLayout = new StaticLayout(getText(), mTextPaint, pageInfo.getPageWidth()/2-otherPadding*3, Layout.Alignment.ALIGN_NORMAL, 1.0f, 1.0f, true);
translate(textX, textY);
draw(canvas);
....

WheregetText()メソッドは、以下のように印刷したい文字列を返します。

String getText()
{
     return "Name and complete address of Genetic Clinic/Ultrasound Clinic/Imaging centre : "+hospital.getName();
}

ここでは、病院名のみを太字にしたいと思います。

4

2 に答える 2

0

次のいずれかの方法で、テキストを太字にすることができます。

呼び出すときに、setTypeface()2 番目のパラメーターを渡すこともできます。 mTextPaint.setTypeface(Typeface.createFromAsset(context.getAssets(),"fonts/times.ttf"), Typeface.BOLD);

またはあなたのxmlで

android:textStyle="bold"
于 2017-01-06T03:42:48.453 に答える
0

これは役立つはずです:

<string name="hospital message">Name and complete address of Genetic Clinic/Ultrasound Clinic/Imaging centre : <b> %1$s </b></string>

その後:

Resources res = getResources();
String text = String.format(res.getString(R.string.hospital_message), hospital.getName());
于 2017-01-06T03:43:54.210 に答える