android app 如何设置自己喜欢的字体
2015-01-08 16:16
696 查看
android系统提供了三种默认的字体样式:bold, normal , italic. 如果你的应用对字体有特殊要求怎么办呢?下面简单说一下具体的操作步骤:
方法一、通过继承TextView等weiget控件
1>在/asset/目录下存放字体文件:/asset/font/myFont.ttf
2>继承实现自己的TextView控件:
public class TitleTextView extends TextView {
public
TitleTextView(Context context, AttributeSet attrs, int defStyle) {
super(context,
attrs, defStyle);
//
TODO Auto-generated constructor stub
init(context);
}
public
TitleTextView(Context context, AttributeSet attrs) {
super(context,
attrs);
//
TODO Auto-generated constructor stub
init(context);
}
public
TitleTextView(Context context) {
super(context);
//
TODO Auto-generated constructor stub
init(context);
}
private
void init(Context context){
Typeface
tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/myFont.ttf");
this.setTypeface(tf);
}
}
3>在你的布局文件中使用即可。
style="@style/PriceOzTextStyleGreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_vertical"
android:text="@string/title_account_center"
android:textSize="@dimen/text_size_large"
android:textStyle="bold"
/>
方法一、通过继承TextView等weiget控件
1>在/asset/目录下存放字体文件:/asset/font/myFont.ttf
2>继承实现自己的TextView控件:
public class TitleTextView extends TextView {
public
TitleTextView(Context context, AttributeSet attrs, int defStyle) {
super(context,
attrs, defStyle);
//
TODO Auto-generated constructor stub
init(context);
}
public
TitleTextView(Context context, AttributeSet attrs) {
super(context,
attrs);
//
TODO Auto-generated constructor stub
init(context);
}
public
TitleTextView(Context context) {
super(context);
//
TODO Auto-generated constructor stub
init(context);
}
private
void init(Context context){
Typeface
tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/myFont.ttf");
this.setTypeface(tf);
}
}
3>在你的布局文件中使用即可。
style="@style/PriceOzTextStyleGreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center_vertical"
android:text="@string/title_account_center"
android:textSize="@dimen/text_size_large"
android:textStyle="bold"
/>
相关文章推荐
- android app 如何设置自己喜欢的字体
- 如何设置android app 的字体大小不受系统字体大小改变的影响
- 安卓app中嵌入一个H5页面,当手机系统设置字体变大时,如何使H5页面的字体不会随用户自己调整的系统字体变化而变化?
- 如何设置android app 的字体大小不受系统字体大小改变的影响
- VC6.0 代码字体 设置 format font 添加自己喜欢的字体
- 如何发布打包并发布自己的Android应用(APP)
- Android APP的字体设置
- 如何在自己的Android APP中加入广告
- (转)如何发布打包并发布自己的Android应用(APP)
- android 如何让appwidget 里面设置TextView 滚动,android widget marquee text
- 如何发布打包并发布自己的Android应用(APP)
- 如何将自己的APP加入android(比如附件的Digitclock)?--学习记录
- 如何发布打包并发布自己的Android应用(APP)
- android主题Theme.Holo.Light下如何设置程序的标题字体颜色为白色 分类: Android界面和组件 2014-06-21 14:02 327人阅读 评论(0) 收藏
- android TextView设置中文字体加粗如何实现
- 如何发布打包并发布自己的Android应用(APP)
- 如何发布打包并发布自己的Android应用(APP)
- Android: 如何向系统设置中添加自己的配置选项及配置页面
- [Android UI界面] 如何在activity中动态的设置TextView上字体的颜色
- 如何在win7系统设置自己喜欢的开始菜单【乡巴佬】