I have set the default font of my application class in the onCreate()
method as detailed in the doc of Calligraphy:
CalligraphyConfig.initDefault(new CalligraphyConfig.
.setDefaultFontPath("fonts/MetaOT-Medi.otf")
.setFontAttrId(R.attr.fontPath)
.addCustomViewWithSetTypeface(CustomViewWithTypefaceSupport.class)
.addCustomStyle(TextField.class, R.attr.textFieldStyle)
.build()
);
I have got a TextView and would like it to fallback using default system font (eg Roboto). May I know how to do it?
Now I circumvent this by copying a set of Roboto font to my assets/fonts folder and then for those TextView I would like to fallback, override the fonts to use it in the xml like fontPath="fonts/Roboto-Regular.ttf"
. Or is there a better solution beside this?
Yes it is possible, which font do you wan to set to which TextView
you can set it in XML or pragmatically.
fontPath="fonts/Roboto-Regular.ttf"
XML Sample Code
<TextView
android:id="@+id/tv_name"
fontPath="fonts/Roboto-Regular.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
pragmatically Sample code
Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Regular.ttf");
setTypeFace(view, tf);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.