0

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.

Capsule
  • 33
  • 3
sodhankit
  • 1,138
  • 1
  • 14
  • 26

2 Answers2

0

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

android:textStyle="bold"
szholdiyarov
  • 385
  • 2
  • 12
0

This should help:

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

and then:

Resources res = getResources();
String text = String.format(res.getString(R.string.hospital_message), hospital.getName());
Shubham
  • 3,071
  • 3
  • 29
  • 46