My question is how to set a custom font for Text component in Facebook's UI framework Litho?
The following is my Text component:
Text.create(componentContext)
.flexGrow(1f)
.verticalGravity(VerticalGravity.CENTER)
.text("MY APP")
.textSizeDip(25)
.textAlignment(Layout.Alignment.ALIGN_CENTER)
To use the
typefaceprop, you must first obtain aTypefaceobject, which is significantly easier if you can use Support Library v26, which introduces Fonts in XML ... it's pretty simple to do so from aComponentContexteven inside youronCreateLayoutmethod (though presumably you may wish to cache theTypeface):There is also a
Typeface.Builderclass available if you do not have access to Support v26, which gives you a few options about how to specify the desired font.