整个项目要使用第三方字体首先将字体文件放到assets文件夹下

因为整个项目要用第三方字体这里我重写了 TextView Button EditText 三个控件

以TextView 为例代码如下 其它控件一样换下继承

public class CustomTextView extends TextView {     public CustomTextView(Context context) {        super(context);        init(context);    }    public CustomTextView(Context context, AttributeSet attrs) {        super(context, attrs);        init(context);    }    public CustomTextView(Context context, AttributeSet attrs, int defSyle) {        super(context, attrs, defSyle);        init(context);    }    /***     * 设置字体     *      * @return     */    public void init(Context context) {         setTypeface(FontCustom.setFont(context));            }}
View Code
public class FontCustom {        static String fongUrl = "fonts/fzltxh_gbk.ttf";    static Typeface tf;    /***     * 设置字体     *      * @return     */    public static Typeface setFont(Context context) {        if(tf==null){            tf = Typeface.createFromAsset(context.getAssets(), fongUrl);        }        return tf;    }}
View Code

使用方法

<CustomTextView                android:layout_width="match_parent"                android:layout_height="wrap_content"                  android:text="我是自定义字体"                android:textColor="@color/login_font_hit"                android:textSize="14.0sp" />
View Code

这样就实现了项目字体统一风格

更多相关文章

  1. Android运行Socket项目 Error: ShouldNotReachHere()
  2. android 自定义输入框,禁止输入表情符号,或者特殊字符
  3. Android之回调函数
  4. 细说:AndroidStudio插件
  5. 布局概述及RelativeLayout布局
  6. Android(安卓)程式开发:(九)使用活动栏 —— 9.3自定义ActionBar项
  7. Android控件之ToggleButton(多状态按钮)
  8. Android二维码开源项目zxing编译
  9. android RelativeLayout常用xml布局属性

随机推荐

  1. Android挂断、接听电话
  2. Android(安卓)推送之Androidpn项目分析(一
  3. Android:自适应不同分辨率的字体大小
  4. android TextView设置删除线,超链接,颜色和
  5. Android(安卓)ROM的制作与烧录
  6. 使用国内镜像加速下载Android(安卓)SDK
  7. 【Android】FragmentPagerAdapter与Fragm
  8. Android控件之HorizontalScrollView 去掉
  9. Android(安卓)Application
  10. Ubuntu 11.10编译Android(安卓)错误