Here is the XML:
There must be a bold / italic / underlined (i.e. target) version of the font. The system does not magically create it for you.
Thus ensure that the target variant of your font is included.
I faced a similar problem with the escaped character <
. You have to use <
instead. For instance:
<string name="greetings"><b>From Russia with love</b></string>
It's written on the official site.
Try using HTML tags in your strings.xml file. This is how you can do it, android string.xml reading html tags problem
To do it programmatically,
TextView t = new TextView(mContext);
t.setText(Html.fromHtml("<b>This is bold</b>"));
there is one method, you can set textview typeface by calling setTypeface method...
textView.setTypeface(null, Typeface.BOLD_ITALIC);
textView.setTypeface(null, Typeface.BOLD);
textView.setTypeface(null, Typeface.ITALIC);
and also refer this link...
Set TextView style (bold or italic)
Most of the answers are correct.
You can also use the so called : SpannableString
You can use it this way :
String bold = "yes !";
String notBold = "no ";
SpannableString text = new SpannableString ( notBold + bold );
text.setSpan ( new StyleSpan ( Typeface.BOLD ) , notBold.length () , text .length () , 0 );
myTextView.setText ( text , BufferType.SPANNABLE );
What is nice about the SpannableString is that you can apply mutliple spans, each on different parts of the string ! As you noticed, I applied the bold type face only on a part of the string (you specify the start and end indexes) , and it should look like this :
no yes !
In the method setSpan, you specify the SPAN to apply, the starting index, the ending index, and flags (I always use 0), in that specific order.
You can even apply other spans, like change the text size (use RelativeSizeSpan ), or even color (use ForegroundColorSpan ), and much more !
Here is an example for the color span, that you can achieve in the following manner :
text.setSpan ( new ForegroundColorSpan ( Color.RED) , 0 , notBold .length () , 0 );
And now, the first part of the string (containing the word no) will be displayed in red !
The font size defined in the dimensions file might not have been picked up during run. Guess you are not running the app in emulator.
Check the following to ensure that its not device thing.