首页 > 其他 > 详细

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

时间:2015-02-09 15:59:45      阅读:291      评论:0      收藏:0      [点我收藏+]

如果在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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!