Skip to content

Font (typeface) management

Sasa Sekulic edited this page Mar 30, 2016 · 2 revisions

ViewBinder has an integrated FontManager that enables you to use custom typefaces in your views. Here's a quick guide:

  1. Put your font files into the assets folder.

  2. When instantiating ViewBinder, register the default font: mViewBinder.getFontManager().setDefaultFont(Typeface.createFromAsset(getAssets(), "Roboto-Regular.ttf"));

  3. Also when instantiating ViewBinder, register all the other fonts that you want to use, with their keywords: mViewBinder.getFontManager().registerFont("light", Typeface.createFromAsset(getAssets(), "Roboto-Light.ttf"));

  4. in the layout XML file, use the ToFont converter to bind the font to the Typeface property: { Typeface @- ToFont(this, 'bold') } or, for the default font { Typeface @- ToFont(this) }. If you mistype the font keyword, it will use the default font. If there's no Typeface property binding, it will behave as a regular widget and use the system font.

Also, take a look at the example code.