Android App Global font settings

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.