码迷,mamicode.com
首页 > 其他好文 > 详细

产品狗你来吧(一)——关于项目中使用第三方字体的自定义TextView

时间:2015-02-09 16:00:46      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:android   自定义字体   ttf   textview   

如果在App设计过程中,有需求要用第三方的ttf字体,那么在项目初期,最好使用一个自定义的TextVIew来做这件事,以免哪天产品狗突然发疯让你换字体的话 ,在项目中一个一个的TextView的去换TypeFace可是要了亲命了.......

那么,如何写这个自定义的TextView呢?看代码........

package com.hackvg.android.views.custom_views;

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * Created by saulmm on 25/01/15.
 */
public class LobsterTextView extends TextView {
    public LobsterTextView(Context context) {

        super(context);

        init(context);
    }

    public LobsterTextView(Context context, AttributeSet attrs) {

        super(context, attrs);

        init(context);
    }

    public LobsterTextView(Context context, AttributeSet attrs, int defStyleAttr) {

        super(context, attrs, defStyleAttr);


        init(context);

    }

    private void init(Context context) {

        Typeface t = Typeface.createFromAsset(context.getAssets(), "Lobster-Regular.ttf");
        this.setTypeface(t);
    }
}
然后,把你下载好的TTF文件放到assets文件夹下就好了,以后如果要换字体,只要把自定义的TextView中的字体换掉即可。

是不是很安心呢?
产品狗 你来吧!

产品狗你来吧(一)——关于项目中使用第三方字体的自定义TextView

标签:android   自定义字体   ttf   textview   

原文地址:http://blog.csdn.net/jasoncol_521/article/details/43671245

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!