-1

I read on Stack Overflow how to create a custom bold font and a regular one:

How to create custom font family with bold font

But I'm struggling to understand how to implement this in my strings. Ordinarily you simply use <b></b> to make text bold, but this doesn't seem to work with my custom fonts. All the text remains the same.

Community
  • 1
  • 1
tore
  • 619
  • 2
  • 9
  • 23
  • You need to provide the bold version of the font as well as the regular one. TTF fonts come in different files for regular, bold, italic bold-italic and so on. I guess otf fonts work the same way. In other words, each file contains a variant of the font-family. – Phantômaxx Nov 08 '18 at 18:05
  • But I have added both a regular and a bold font... – tore Nov 08 '18 at 18:21
  • There may be something wrong the way you made the custom font. – Phantômaxx Nov 08 '18 at 19:11

1 Answers1

0

I know that you have tried adding the bolded font to a font family, but it hasn't worked. You can try one of the ways below. It will work even if you do import a TTF font.

One way you can do it is in strings.xml You can create a new string and then add the b to bold it like this:

<string name="my_string"><b> My String</b></string>

You will need to create one for each string that you want to bold. Then in your layout file, you can set the android:text to one of the strings from strings.xml and you can set the android:fontFamilyto the TTF font.

You can also bold it programmatically using the SpannableString in Java. Check this article to see how to bold programmatically. Hope it helps!

Ishaan Javali
  • 1,711
  • 3
  • 13
  • 23