# Android Custom font styles

Source: Internet
Author: User

# Android Custom font styles

The Custom font settings in Android are generally set through the facetype attribute. First, let's take a look at the methods provided on the official website.

As the name implies, we can set the font by using the asset file under the assets file in the project or the system file of android.
To use the assets method, first create the assets folder in the project path,
After setting the file, you can use

     Typeface typeface1 = Typeface.createFromAsset(this.getAssets(),"fonts/1.TTF");     tvText1.setTypeface(typeface1);

Method or a subclass of TextView

public class MyTextView extends TextView {public MyTextView(Context context) {    super(context);}public MyTextView(Context context, AttributeSet attrs) {    super(context, attrs);}public MyTextView(Context context, AttributeSet attrs, int defStyleAttr) {    super(context, attrs, defStyleAttr);}@Overridepublic void setTypeface(Typeface tf, int style) {    super.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "2.tff"));}

}

If a system file is used, you must note that the path setting must start with "system" When referencing it.

Typeface tf = Typeface.createFromFile("/system/fonts/AndroidClock.ttf")

You can use these methods to customize TextView text styles.

Related Article

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.