Android—解决重写TextView设置字体大量引用后卡屯的问题
来源:互联网 发布:mac推出键 编辑:程序博客网 时间:2024/05/17 22:44
我在http://blog.csdn.net/weiguishan/article/details/46678935这边博客谢了两种方法,自定义textview字体,在xml里面大量引用会卡顿,下面给出解决办法。
首先写一个类,继承Application,在该类的oncreate方法获取Typeface
public class BusinessApplication extends Application {
public static Typeface texttypeface = null;
public static Typeface digitaltypeface = null;
@Override
public void onCreate() {
//生成字体库文件
texttypeface = Typeface.createFromAsset(getApplicationContext().getAssets(),"fonts/weiruanyahei.ttf");
}
}
然后,在继承TextView的自定义类里面
package com.insightcode.androidfont;
import com.insightcode.app.BusinessApplication;
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;
/**
* 文本为汉子,设置微软雅黑
*
*/
public class FontTextTextView extends TextView {
private Context mContext=null;
Typeface texttypeface=null;
public FontTextTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if(mContext==null){
this.mContext = context;
}
if(texttypeface==null){
texttypeface = BusinessApplication.texttypeface;
}
this.setTypeface(texttypeface);
}
public FontTextTextView(Context context, AttributeSet attrs) {
super(context, attrs);
if(mContext==null){
this.mContext = context;
}
if(texttypeface==null){
texttypeface = BusinessApplication.texttypeface;
}
this.setTypeface(texttypeface);
}
public FontTextTextView(Context context) {
super(context);
if(mContext==null){
this.mContext = context;
}
if(texttypeface==null){
texttypeface = BusinessApplication.texttypeface;
}
this.setTypeface(texttypeface);
}
}
在xml里面引用即可
- Android—解决重写TextView设置字体大量引用后卡屯的问题
- android-textView-字体的设置
- Android TextView字体的设置
- Android 解决TextVIew加载自定义字体慢的问题
- 弱引用的场景——解决android gridView加载大量图片的性能问题
- android TextView 字体设置
- Android TextView字体设置
- Android textview设置字体
- Android设置TextView字体
- 重写TextView解决HorizontalScrollView中TextView显示不全的问题
- android textview设置字体的行距
- Android代码中设置TextView的字体
- Android中TextView的字体颜色设置
- 解决Android中TextView单行设置过时的问题
- 解决重写的TextView跑马灯一直跑的问题
- Android TextView设置字体风格
- ANDROID TEXTVIEW 设置字体颜色
- Android TextView设置字体风格
- 大小端问题
- [USACO Open08]牛的邻居Cow Neighborhoods解题报告
- maven 添加自定义jar 命令行
- 网络故障:DNS ???
- 斐波那契数列-数组和递归-C语言
- Android—解决重写TextView设置字体大量引用后卡屯的问题
- 授权远程连接MySQL(Linux)
- 投简历时的五个准备八大纪律
- 8种Nosql数据库系统对比
- C ++ 虚函数 (转)
- 如何解决Django 1.8在migrate时失败?
- 黑马程序员---java中如何实现线程范围内共享数据
- 杂七杂八的分享
- Hadoop第七讲(1)