Is there any way to make some text bold of a static layout? I am trying to print one government document so that I have used StaticLayout using following code to set text on 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);
....
Where getText()
method returns the String which I want to print as given below.
String getText()
{
return "Name and complete address of Genetic Clinic/Ultrasound Clinic/Imaging centre : "+hospital.getName();
}
So Here I want to make hospital name bold only.
You can make text bold in either ways:
When you call
setTypeface()
you can also pass second parameter:mTextPaint.setTypeface(Typeface.createFromAsset(context.getAssets(),"fonts/times.ttf"), Typeface.BOLD);
OR in your xml