我正在尝试装饰我的应用程序字体。我可以在代码中做到这点。但不知道如何在设置中执行此操作。在代码中,我这样做
public class Fonts {
public static Typeface getHeaderFont(Context context){
return Typeface.createFromAsset(context.getAssets(), "header_levelI.ttf");
}
public static Typeface getSubHeaderFont(Context context){
return Typeface.createFromAsset(context.getAssets(), "header_levelII.ttf");
}
}和
Typeface type= Fonts.getHeaderFont(getActivity());
TextView header = (TextView) v.findViewById(R.id.cassaName);
header.setTypeface(type);设置android studio只有标准字体。如何在文件中指定字体而不编写额外的代码?
发布于 2014-12-09 19:06:17
使用您的自定义字体创建自定义TextView。
注意:将所需的字体文件放在assets/fonts目录中非常重要。
public class CustomTextView extends TextView {
public CustomTextView(Context context) {
super(context);
setFont();
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
setFont();
}
public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setFont();
}
private void setFont() {
Typeface font = Typeface.createFromAsset(getContext().getAssets(),"fonts/ss-symbolicons-line.ttf");
setTypeface(font, Typeface.NORMAL);
}
}https://stackoverflow.com/questions/27375070
复制相似问题