创建自定义TextView
这样的:
public class DINOTMediumTextView extends TextView {
public DINOTMediumTextView(Context context) {
super(context);
setCustomFont(context);
}
public DINOTMediumTextView(Context context, AttributeSet attrs) {
super(context, attrs);
setCustomFont(context);
}
public DINOTMediumTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setCustomFont(context);
}
private void setCustomFont(Context context) {
Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/DINOT-Medium.otf");
setTypeface(tf);
}
}
把字体的文件中assets/fonts/
(创建资产的文件夹中的文件夹)
,然后在你的布局XML:
<com.yourapp.views.DINOTMediumTextView
android:id="blabla"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
com.yourapp.views
是包含您的DINOTMediumTextView
类的包的名称。
该代码似乎没问题。尝试使用不同的字体进行测试。我不知道什么是otf,但你可以尝试一下ttf。例如与此:http://www.microsoft.com/typography/fonts/font.aspx?FMID=1131 – Caner
完全otf扩展导致的问题,必须是tf – vallllll