首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义TextView的呈现错误

自定义TextView的呈现错误
EN

Stack Overflow用户
提问于 2016-09-30 07:50:00
回答 1查看 728关注 0票数 0

我有一个针对特定字体的自定义文本视图类。

我的班:‘

代码语言:javascript
复制
public LobsterTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    Typeface face=Typeface.createFromAsset(context.getAssets(), "lobster1_4.otf");
    this.setTypeface(face);
}

public LobsterTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    Typeface face=Typeface.createFromAsset(context.getAssets(), "lobster1_4.otf");
    this.setTypeface(face);
}

}

我的布局:

代码语言:javascript
复制
 <x.y.z.LobsterTextView
        android:id="@+id/tv_mobile_name"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:textSize="@dimen/font_large3"
        android:layout_marginTop="@dimen/fab_margin"
        android:layout_marginLeft="@dimen/fab_margin"
        android:textColor="@color/colorAccent_3"
        android:text="Register with Pika" />

和错误:‘呈现问题--无法实例化以下类:- io.pika.pike_store.utils.LobsterTextView (Open,Show,清除缓存)提示:使用自定义视图中的android.graphics.Typeface.createAssetUid(Typeface.java:219) ()跳过代码或显示示例数据时,在IDE异常详细信息中显示,java.lang.NullPointerException在io.pika.pike_store.utils.LobsterTextView.(LobsterTextView.java:22),io.pika.pike_store.utils.LobsterTextView.(LobsterTextView.java:22),at at java.lang.reflect.Constructor.newInstance(Constructor.java:423),at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)在android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858))在android.view.LayoutInflater.rInflate(LayoutInflater.java:834)中,重水化,重熔,在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821),重熔,在android.view.LayoutInflater_Delegate.parseInclude(LayoutInflater_Delegate.java:197),变价,在android.view.LayoutInflater.parseInclude(LayoutInflater.java:902),改性,改性,再加工,再加工,android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70),android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70),android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70),android.view。LayoutInflater.rInflate(LayoutInflater.java:834)在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)上进行辅助处理,在android.view.LayoutInflater.inflate(LayoutInflater.java:518)上进行分级,在android.view.LayoutInflater.inflate(LayoutInflater.java:397)上复制堆栈,剪贴板,LobsterTextView自定义视图是最近编辑的,而不是上一次构建:构建项目。

我的代码一旦运行fine.but,当我进入布局文件时,这个错误总是出现在前台。

我怎样才能解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2016-09-30 07:54:03

公共类PahariTextView扩展TextView {

代码语言:javascript
复制
public PahariTextView(Context context) {
    super(context);

    applyCustomFont(context);
}

public PahariTextView(Context context, AttributeSet attrs) {
    super(context, attrs);

    applyCustomFont(context);
}

public PahariTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    applyCustomFont(context);
}

private void applyCustomFont(Context context) {
    Typeface customFont = FontCache.getTypeface("fonts/quicksand_light.otf", context);
    setTypeface(customFont);
}

}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39786332

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档