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
typeface
prop, you must first obtain aTypeface
object, which is significantly easier if you can use Support Library v26, which introduces Fonts in XML ... it's pretty simple to do so from aComponentContext
even inside youronCreateLayout
method (though presumably you may wish to cache theTypeface
):There is also a
Typeface.Builder
class available if you do not have access to Support v26, which gives you a few options about how to specify the desired font.