Android App text font settings

Source: Internet
Author: User

First step: Create a new Android project, create a new folder in the assets directory, the name can be arbitrary,
I'm named fonts here.
Step two: Copy the font file to this new directory (there are many font files in the C:\Windows\Fonts directory in the Windows system)
Step three, create a static method under Mainactivity

//Because reading a font file into memory is a time-consuming operation, if the font file is larger, there will beIt is obvious that the typeface can be defined as a global variable, then you can add a judgment, if the typeface exists, it is called directly, if it does not exist, then create, so that the words can only be read into one time, do not have to read in every time Public StaticTypeface Typeface; Public Static void setfonts(Context Context,textview TV) {if(typeface==NULL){//The font file is read into memory and becomes a font file objectAssetmanager mgr = Context.getassets ();//Strictly case-sensitive, extension.String Path ="Fonts/impact. TTF ";        typeface = Typeface.createfromasset (mgr, path); }//Use typeface font file ObjectTv.settypeface (typeface); }//Apply FontSetfonts (CONTEXT,TV);

Android App text 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.