0

I want to display one string which contain some dynamic and static data.I want regular custom font for dynamic data and light font for static data

Below is the string i have mention in string.xml

<string name="my_string"> <![CDATA[<b><font color=#000000> %1$s </font></b>]]>  posted a<![CDATA[<b><font color=#000000> Something </font></b>]]> that matches your preferences at</string>

I have declare light font in textview but how an i give regular font for dynamic data.

Rajat
  • 763
  • 11
  • 17
  • Use Spannable class for it. check this - http://stackoverflow.com/questions/14840247/spannable-on-android-for-textview – Wasim K. Memon Mar 08 '17 at 11:21
  • i have already go through all spannable example but it does give me hint for custom font rendering. – Rajat Mar 08 '17 at 11:34

1 Answers1

0

What you can do is apply light font on text view using set typeface method and then apply spannable class on other text with regular style or bold style. so it will look as you want

tView.setTypeface(lightTypefaceObject);

SpannableString spannablecontent=new SpannableString("Normal Font Style Text");
spannablecontent.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 
                         0,spannablecontent.length(), 0);
// set Text here
tView.setText(spannablecontent);
Wasim K. Memon
  • 5,979
  • 4
  • 40
  • 55