I'm creating a custom View
class that displays text using a StaticLayout
with a custom typeface loaded from a .ttf
asset file. The basic look of the typeface is a serif font and the TrueType properties in the font file indicate that it's serif. Nevertheless, for characters not in the font, Android falls back to a sans-serif typeface (it looks like Roboto or Noto, depending on the Android version).
Is there a way to control this so that the Android layout engine falls back to a serif typeface? (Like maybe some magic string to pass to Paint#setFontFeatureSettings()
, or perhaps a way to specify a stack of typefaces for use in a Paint
?)
Any solution would have to work when the app is distributed, so playing games with Android's system configuration files is not an option. Also, I'm aware of this question (that is still unanswered after four years), but my problem is a bit different, although the solution to both issues might very well be the same.
FontFamily
class appears to be in the dark gray list, so isn't accessible even through reflection. (See developer.android.com/about/versions/pie/…). – Anderer