I have several fonts with different styles, lets say: "MyFont_default.otf", "MyFont_italic.otf", "MyFont_bold.otf"
Normally, I would set the font of a TextView like this:
Typeface tf=Typeface.createFromAsset(context.getAssets(), "MyFont_italic.otf");
textView.setTypeface(tf);
And my question is: is it possible to combine all these fonts, into one single font, say "MyFont", and depending of the TextView style defined in the XML layout file (italic, bold), the TextView to be displayed in the appropriate font?
Use some sort of font editor to combine the fonts into a single file. Many fonts come with multiple styles in a single file, which is what you would need in this case.
I don't have the proper reputation to comment but I can confirm, that approaches work.
Using FontForge (binary available for Windows):
- Open your multiple .otf files with FontForge (Regular, Bold, Italic).
- Make sure to select the window showing the "Regular" version of the font
- Use File > Save ttc from that window
- See that indeed the other sub fonts are listed in the save dialog (bold, italic)
- Save and use this ttc file in Android
I tested it with an html text displayed in a TextView :
<b>Test</b> Test <i>Test</i>
->
"Test Test Test" which didn't work previously in Android 2.3.7 and with this ttc font all three versions of the text show perfectly.
As I said, it's important to select the Regular font when exporting because that's the one Android uses as "default" (I did an export first from the Bold version and it was all Bold).