0

有什么方法可以使静态布局的某些文本变为粗体?我正在尝试打印一份政府文件,以便我使用 StaticLayout 使用以下代码在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()您还可以传递第二个参数: 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 回答