Andorid 设置 自定义 字体
来源:互联网 发布:暗黑破坏神2 mac 1.13 编辑:程序博客网 时间:2024/05/22 01:37
1. 现在吧字体读出来
放在 Application中 要整成单例模式
privatestaticTypefaceEnglishAndNumTypeface;
privatestaticTypefaceChineseTypeface;
publicstaticTypeface getEnglishAndNumTypeface(Context context) {
if(EnglishAndNumTypeface==null) {
EnglishAndNumTypeface= Typeface.createFromAsset(context.getAssets(),"fonts/HelveticaLight.ttf");
}
returnEnglishAndNumTypeface;
}
publicstaticTypeface getChineseTypeface(Context context) {
if(ChineseTypeface==null) {
ChineseTypeface= Typeface.createFromAsset(context.getAssets(),"fonts/Chines_lantingheijian.ttf");
}
returnChineseTypeface;
}
2. 获取TextView
TextView numView = (TextView) itemView.findViewById(R.id.number);
3. 设置字体
numView .setTypeface( NiceCDApplication.getTypeface( getActivity()));
第二种方法
自己写 TextView 然后 在xml 直接使用该TextView
publicclassTextViewWithChineseFontextendsTextView {
publicTextViewWithChineseFont(Context context, AttributeSet attrs,intdefStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
publicTextViewWithChineseFont(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
publicTextViewWithChineseFont(Context context) {
super(context);
init();
}
privatevoidinit() {
this.setTypeface(NiceCDApplication.getChineseTypeface(getContext()));
}
}
然后在 xml 中使用该View
<com.zuimeia.suite.nicecountdown.widget.fontview.TextViewWithChineseFont
android:id="@+id/introduction_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginTop="10dp"
android:text="@string/introduction"
android:textSize="@dimen/font_size_large"/>
0 0
- Andorid 设置 自定义 字体
- iOS 设置字体 自定义字体
- iOS 设置字体 自定义字体
- iOS 设置字体 自定义字体
- css 设置自定义字体
- TextView设置自定义字体
- Android设置自定义字体
- 自定义texview 设置自定义字体
- android 设置自定义字体为默认字体
- Balsamiq Mockups自定义字体设置
- android 自定义字体 typeface设置
- android TextView设置自定义字体
- android SpannableStringBuilder设置自定义字体
- Android Studio设置自定义字体
- Android TextView 自定义字体设置
- andorid,动态设置TextView文本中字体的颜色和格式,用Html.fromHtml方法
- Linux语言和字体的自定义设置
- IOS 设置使用自定义字体(Xcode4)
- 黑马程序员-Java的集合类(泛型、可变参数、for-each循环和静态导入)
- 通过nat模式实现虚拟机下linux与电脑主机的互通
- mysql group by
- android利用FTP实现文件共享
- ECS Linux开启/关闭swap(虚拟内存)
- Andorid 设置 自定义 字体
- MyBatis学习三:SqlMapConfig.xml属性和sql片段
- Android源码分析:AudioFlinger中的线程
- Add Digits
- objective-c实现authCode 解决php与ios通信加密的问题
- Maven异常
- ldp报文协商过程
- C++中值传递、指针传递、引用传递的总结
- 别的程序员是怎么读你的简历的