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 {
}
3>在你的布局文件中使用即可。