#Android Custom Font Styles

Source: Internet
Author: User

Custom font settings in Android are generally set through the Facetype property, first look at the methods provided by the official website

As the name implies, we can use the asset files under the assets file in the project or the system files of Android itself to make font settings.
If you use the assets method, first we need to create the assets folder under the project path.
, after you have set up the file, you can use

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

method or customize a TextView subclass

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 you use system files, the path settings need to be aware that the path setting needs to start at the time of the reference.

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

With these methods, you can implement a custom TextView text style

#Android Custom Font Styles

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.