您的位置:首页 > 移动开发

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"
/>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: