Android 自定义字体
来源:互联网 发布:免费配音制作软件 编辑:程序博客网 时间:2024/05/22 13:58
在android系统中,自带的只有三种字体---"sans","serif"和"monospace",你只要在xml文件中的
android:typeface
android:typeface属性使用它们:
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView
android:text="sans:"
android:layout_marginRight="4px"
android:textSize="20sp"
/>
<TextView
android:id="@+id/sans"
android:text="Hello, world!"
android:typeface="sans"
android:textSize="20sp"
/>
</TableRow>
<TableRow>
<TextView
android:text="serif:"
android:layout_marginRight="4px"
android:textSize="20sp"
/>
<TextView
android:id="@+id/serif"
android:text="Hello, world!"
android:typeface="serif"
android:textSize="20sp"
/>
</TableRow>
<TableRow>
<TextView
android:text="monospace:"
android:layout_marginRight="4px"
android:textSize="20sp"
/>
<TextView
android:id="@+id/monospace"
android:text="Hello, world!"
android:typeface="monospace"
android:textSize="20sp"
/>
</TableRow>
<TableRow>
<TextView
android:text="Custom:"
android:layout_marginRight="4px"
android:textSize="20sp"
/>
<TextView
android:id="@+id/custom"
android:text="Hello, world!"
android:textSize="20sp"
/>
</TableRow>
</TableLayout>
有时候,系统自带的字体并不能满足我们特殊的需求,这时候就需要引用其他的字体了,可以把下载的字体文件放在assets目录下.自定义字体文件不能使用xml代码读取而应该使用java代码:
public class Test extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
TextView tv=(TextView)findViewById(R.id.custom);
Typeface face=Typeface.createFromAsset(getAssets(),
"fonts/HandmadeTypewriter.ttf");//也可以使用其他的静态方法获取
tv.setTypeface(face);
}
}
TTF文件下载:Windows.zip | MAC.zip(选择对应的系统)
注意:如果你下载的字体Android不支持,那么系统会使用默认字体"sans"。由于应用自定义字体需要额外空间,所以一般不是都需要自定义字体的.
原文地址:http://www.androidmi.com/Androidkaifa/jinjie/201011/1632.html
- Android 使用自定义字体
- Android开发:自定义字体
- Android自定义字体
- android自定义字体
- Android 使用自定义字体
- Android 自定义字体
- android应用自定义字体
- Android 自定义字体
- Android 自定义字体
- Android自定义字体方法
- android 自定义字体
- android自定义字体
- Android自定义字体实现
- Android 自定义字体
- android应用自定义字体
- Android 自定义字体 例子
- Android自定义字体
- #Android 自定义字体样式
- Oracle ORA-07445 [evaopn3()+384] 错误 分析
- sql2005维护计划
- Re: How to use values of properties file in selenium code - msg#02103
- VS 快捷键
- Cloud Found使用dev_setup进行单节点部署之排错分析
- Android 自定义字体
- Linux 的多线程编程的高效开发经验
- 动态规划求编辑距离
- 解决Three20与其他framework冲突的办法
- 先思考,再发问
- UNIX系统编程2《笔记》
- 2011 福州赛区现场赛C - Bob’s Race
- repeater控件分成两列显示
- java设计模式_命令模式