Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android的StaticLayout中加粗一些文本_Android_Staticlayout - Fatal编程技术网

在android的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

有没有办法使静态布局的某些文本加粗?我正试图打印一份政府文件,因此我使用了StaticLayout,使用以下代码在
画布上设置文本

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());