Believe that a lot of the design of the pursuit of the ultimate developers are not satisfied with the default font of the Android system, this time need to use a custom font, of course, you can use the system-provided typeface to load custom fonts, but, one by one textview settings, is not soon crazy, This article shows you how to quickly define a custom app global font
The easy way to do this is to use one of the open source libraries on GitHub calligraphy, which takes only a few steps
- Add dependencies in Androidstudio, search calligraphy Click Add (if you haven't used Androidstudio, we recommend switching to this Google Official development tool)
- Custom application, configure default fonts in OnCreate
>calligraphyconfig.initdefault (New Calligraphyconfig.builder (). Setdefaultfontpath ("Fonts/Roboto-Bold.ttf"). Setfontattrid (R.attr.fontpath). build ());
-Overriding the Attachbasecontext method in activity (it is recommended that all activity in a baseactivity,app inherit from baseactivity)
>super.attachbasecontext (Calligraphycontextwrapper.wrap (newbase));
In this way, the default font for TextView is the Roboto-bold font you set, and if you want to set other fonts separately for TextView, you can use Fontpath directly in XML or style. Please refer to the Calligraphy Readme document and sample samples program on GitHub for a variety of usage methods.
Android App Global font settings