android中字体设置Typeface的使用
2016-11-18 13:41
525 查看
第一种字体设置方法:
方法一:XML中使用android默认字体, Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace”
... Android:text="Hello,World" Android:typeface="sans" Android:textSize="20sp" />
... Android:text="Hello,World" Android:typeface="serif" Android:textSize="20sp" />
... Android:text="Hello,World" Android:typeface="monospace" Android:textSize="20sp" />
方法二:在Android中可以引入其他字体,首先要将字体文件(*.ttf)保存在assets/fonts/目录下
1.... Android:text="Hello,World" Android:textSize="20sp" />
2. java程序中引入其他字体关键代码
//得到TextView控件对象 TextView textView =(TextView)findViewById(R.id.custom); //将字体文件保存在assets/fonts/目录下,创建Typeface对象 Typeface typeFace =Typeface.createFromAsset(getAssets(),"fonts/HandmadeTypewriter.ttf"); //使用字体 textView.setTypeface(typeFace);
第二种字体设置方法
Paint mp = new paint(); mp.setTypeface(Typeface.DEFAULT_BOLD)
常用的字体类型名称还有:
Typeface.DEFAULT //常规字体类型
Typeface.DEFAULT_BOLD //黑体字体类型
Typeface.MONOSPACE //等宽字体类型
Typeface.SANS_SERIF //sans serif字体类型
Typeface.SERIF //serif字体类型
除了字体类型设置之外,还可以为字体类型设置字体风格,如设置粗体:
Paint mp = new Paint(); Typeface font = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD); p.setTypeface( font );
常用的字体风格名称还有:
Typeface.BOLD //粗体
Typeface.BOLD_ITALIC //粗斜体
Typeface.ITALIC //斜体
Typeface.NORMAL //常规
但是有时上面那些设置在绘图过程中是不起作用的,所以还有如下设置方式:
Paint mp = new Paint(); mp.setFakeBoldText(true); //true为粗体,false为非粗体 mp.setTextSkewX(-0.5f); //float类型参数,负数表示右斜,整数左斜 mp.setUnderlineText(true); //true为下划线,false为非下划线 mp.setStrikeThruText(true); //true为删除线,false为非删除线
转载: http://blog.sina.com.cn/s/blog_66cf0e740101axqw.html
相关文章推荐
- 【Android每日一讲】2012.10.29 控制不同的文字字体 -- Typeface对象使用
- Android字体Typeface设置
- Android中通过typeface设置字体
- android 字体TypeFace设置.
- Android中通过typeface设置字体
- Android中通过typeface设置字体
- Android中应用的字体Typeface的设置
- Android中通过typeface设置字体
- Android 字体设置-Typeface讲解
- Android中通过typeface设置字体
- [Android] 字体使用dp单位避免设置系统字体大小对排版的影响
- Android字体设置,Roboto字体使用
- Android中通过typeface设置字体
- Android 中文字体的设置方法和使用技巧
- Android中通过typeface设置字体
- Android字体Typeface设置
- Android字体设置,Roboto字体使用
- Android中通过typeface设置字体 textAppearance设置文字外观
- [Android] 字体使用dp单位避免设置系统字体大小对排版的影响
- Android中通过typeface设置字体