I hope this help you ;)
FontUtil class
public class FontUtil {
private static Typeface mTitleFont;
private static Typeface mContentFont;
public static enum FontType {
TITLE_FONT {
public String toString() {
return "fonts/InterstateCondMonoLgt.ttf";
}
},
CONTENT_FONT {
public String toString() {
return "fonts/InterstateLight.ttf";
}
}
}
/**
* @return Typeface Instance with the font passed as parameter
*/
public static Typeface getTypeface(Context context, String typefaceName) {
Typeface typeFace = null;
try {
if (typefaceName.equals(FontType.TITLE_FONT.toString())) {
if (mTitleFont == null) {
mTitleFont = Typeface.createFromAsset(context.getAssets(), typefaceName);
}
typeFace = mTitleFont;
} else if (typefaceName.equals(FontType.CONTENT_FONT.toString())) {
if (mContentFont == null) {
mContentFont = Typeface.createFromAsset(context.getAssets(), typefaceName);
}
typeFace = mContentFont;
}
} catch (Exception ex) {
typeFace = Typeface.DEFAULT;
}
return typeFace;
}
/**
* @return Typeface Instance with the font passed as parameter
*/
public static Typeface getTypeface(Context context, FontType typefaceName) {
return getTypeface(context, typefaceName.toString());
}
}
Client
protected void onPostExecute(Article result) {
super.onPostExecute(result);
TextView txtTitle= (TextView) view.findViewById(R.id.title);
txtTitle.setTypeface( FontUtil.getTypeface(mContext, FontType.TITLE_FONT) );
txtTitle.setText(result.getTitle());
TextView txtMain= (TextView) view.findViewById(R.id.main);
txtMain.setTypeface( FontUtil.getTypeface(mContext, FontType.CONTENT_FONT) );
txtMain.setText(result.getContent());
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…