android自定义字体
2011-10-19 14:34
190 查看
1. 定义包含1 TextView 布局:main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
/>
</LinearLayout>
2. 下载字体文件 后缀名一般为:*.ttf 如:本例为:biscuit_tin.ttf
* 在工程目录下的 assets 目录下新建文件夹:fonts 然后把*.ttf文件 复制至该目录 并刷新工程
public class MyTextTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Typeface fontFace = Typeface.createFromAsset(getAssets(), "fonts/biscuit_tin.ttf");
TextView text = (TextView)findViewById(R.id.text);
text.setTypeface(fontFace);
text.setText("Hello World!");
text.setTextSize(100);
}
}
考虑版权问题 *.ttf 字体文件 要大家自己找了 网络上有很多 我一直在找 微软雅黑 可惜失败 题外话 microsoft-vista 的贡献也仅于此了....
emulator 运行截图: text="Hello World!"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
/>
</LinearLayout>
2. 下载字体文件 后缀名一般为:*.ttf 如:本例为:biscuit_tin.ttf
* 在工程目录下的 assets 目录下新建文件夹:fonts 然后把*.ttf文件 复制至该目录 并刷新工程
public class MyTextTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Typeface fontFace = Typeface.createFromAsset(getAssets(), "fonts/biscuit_tin.ttf");
TextView text = (TextView)findViewById(R.id.text);
text.setTypeface(fontFace);
text.setText("Hello World!");
text.setTextSize(100);
}
}
考虑版权问题 *.ttf 字体文件 要大家自己找了 网络上有很多 我一直在找 微软雅黑 可惜失败 题外话 microsoft-vista 的贡献也仅于此了....
emulator 运行截图: text="Hello World!"
相关文章推荐
- Android:更好的自定义字体方案
- 【完美解决】android开发 自定义字体安装包过大的问题
- Android自定义字体方法
- Android 全局替换第三方字库(自定义字体)
- Android textView字体自定义结合HTml
- Android Webview使用自定义字体加载网页
- Android自定义字体类库Calligraphy--快速实现自定义应用字体
- 【Android Demo】让Android支持自定义的ttf字体
- Android 自定义字体,字替换为图片
- Android更换系统默认显示的字体使用自定义字体
- Android 自定义 spinner (背景、字体颜色)
- Android 特效库 - 实现自定义字体
- Android 自定义 spinner (背景、字体颜色)
- Android SearchView 自定义SearchIcon和字体颜色大小
- Android:更好的自定义字体方案
- 盘点Android使用自定义字体遇到的坑
- Android自定义view(Textview 数字滚动)->paint类相关->字体渲染相关
- Android笔记:在APP里面使用自定义字体
- Android 开发使用自定义字体
- android 自定义字体 字体库 字体格式 使用攻略