码迷,mamicode.com
首页 > 移动开发 > 详细

#Android 自定义字体样式

时间:2015-06-02 17:57:33      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:textview   android   facetype   字体   founds   

技术分享

Android中自定义字体设置一般通过 facetype属性进行设置,先看一下官网提供的方法
技术分享
顾名思义 就是说我们可以通过使用项目中assets文件下的资产文件或者是android本身的系统文件进行字体设置。
如果使用assets方法的话,首先我们需要在项目路径下创建assets文件夹,技术分享
如图所示,设置好文件之后,可以使用

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

方法 或者 自定义一个 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);
}

@Override
public void setTypeface(Typeface tf, int style) {
    super.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "2.tff"));
}

}

如果使用系统文件的话,在引用的时候路径设置需要注意路径的设置需要一system开头

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

通过这些方法均可以实现自定义的TextView的文本样式

#Android 自定义字体样式

标签:textview   android   facetype   字体   founds   

原文地址:http://blog.csdn.net/u011068996/article/details/46331773

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