Android中通过typeface设置字体
2015-06-09 08:47
375 查看
转载地址:http://www.cnblogs.com/bravestarrhu/archive/2012/07/17/2595598.html
Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace",除此之外还可以使用其他字体文件(*.ttf)
方法一:XML中使用android默认字体
<!-- 使用默认的sans字体-->
<TextView Android:id="@+id/sans"
Android:text="Hello,World"
Android:typeface="sans"
Android:textSize="20sp" />
<!-- 使用默认的serifs字体-->
<TextView Android:id="@+id/serif"
Android:text="Hello,World"
Android:typeface="serif"
Android:textSize="20sp" />
<!-- 使用默认的monospace字体-->
<TextView Android:id="@+id/monospace"
Android:text="Hello,World"
Android:typeface="monospace"
Android:textSize="20sp" />
方法二:在Android中可以引入其他字体,首先要将字体文件保存在assets/fonts/目录下
1. <!-- 这里没有设定字体,将在Java代码中设定-->
<TextView Android:id="@+id/custom"
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);
Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace",除此之外还可以使用其他字体文件(*.ttf)
方法一:XML中使用android默认字体
<!-- 使用默认的sans字体-->
<TextView Android:id="@+id/sans"
Android:text="Hello,World"
Android:typeface="sans"
Android:textSize="20sp" />
<!-- 使用默认的serifs字体-->
<TextView Android:id="@+id/serif"
Android:text="Hello,World"
Android:typeface="serif"
Android:textSize="20sp" />
<!-- 使用默认的monospace字体-->
<TextView Android:id="@+id/monospace"
Android:text="Hello,World"
Android:typeface="monospace"
Android:textSize="20sp" />
方法二:在Android中可以引入其他字体,首先要将字体文件保存在assets/fonts/目录下
1. <!-- 这里没有设定字体,将在Java代码中设定-->
<TextView Android:id="@+id/custom"
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);
相关文章推荐
- flash 系统字体显示问题
- 谈谈网页设计中的字体应用Font Set
- PDF里的文字显示模糊的解决方法
- 保证可下载的漂亮动作2008奥运比赛项目字体
- 网页设计中的 serif 和 sans-serif字体应用
- Android的TextView与Html相结合的具体方法
- Android中实现为TextView添加多个可点击的文本
- ExtJs默认的字体大小改变的几种方法(自己整理)
- 一个实现字体大中小方法的JavaScript代码
- php修改NetBeans默认字体的大小
- android textview 显示html方法解析
- Android开发技巧之在a标签或TextView控件中单击链接弹出Activity(自定义动作)
- Android实现TextView中文字链接的4种方式介绍及代码
- android TextView属性的详细介绍 分享
- 如何解决修改StaticText的字体
- asp.net调用系统设置字体文本框的方法
- linux BASH shell下设置字体及背景颜色
- 在shell或者perl中改变字体或背景的颜色
- android TextView加下划线的方法
- android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法