在android的StaticLayout中加粗一些文本
有没有办法使静态布局的某些文本加粗?我正试图打印一份政府文件,因此我使用了StaticLayout,使用以下代码在在android的StaticLayout中加粗一些文本,android,staticlayout,Android,Staticlayout,有没有办法使静态布局的某些文本加粗?我正试图打印一份政府文件,因此我使用了StaticLayout,使用以下代码在画布上设置文本 TextPaint mTextPaint=new TextPaint(); mTextPaint.setTypeface(Typeface.createFromAsset(context.getAssets(),"fonts/times.ttf")); StaticLayout mTextLayout; canvas.save(); mTextLa
画布上设置文本
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);
....
其中getText()
方法返回我要打印的字符串,如下所示
String getText()
{
return "Name and complete address of Genetic Clinic/Ultrasound Clinic/Imaging centre : "+hospital.getName();
}
所以这里我只想把医院的名字加粗 您可以通过以下两种方式将文本加粗:
调用setTypeface()
时,还可以传递第二个参数:
mTextPaint.setTypeface(Typeface.createFromAsset(context.getAssets(),“font/times.ttf”),Typeface.BOLD)代码>
或者在xml中
android:textStyle="bold"
这将有助于:
<string name="hospital message">Name and complete address of Genetic Clinic/Ultrasound Clinic/Imaging centre : <b> %1$s </b></string>
我不想将所有文本都加粗,我只想将医院名称加粗。您是否在静态布局中设法将一些文本加粗?我非常感谢您的帮助。在我的问题中,我是从java传递字符串,而不是从资源文件传递字符串。
Resources res = getResources();
String text = String.format(res.getString(R.string.hospital_message), hospital.getName());