Android FontFamily在升级支持库后不适用

Android FontFamily在升级支持库后不适用,android,layout,Android,Layout,我有一个文本视图: <TextView android:id="@+id/digits" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="13dp" android:tr

我有一个文本视图:

<TextView
        android:id="@+id/digits"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="13dp"
        android:translationY="5dp"
        android:text=""
        android:textSize="128sp"
        android:textColor="@color/white"
        android:fontFamily="fonts/Roboto-Thin.ttf"
/>
一切都很好,TextView有合适的字体和字体

但是,当我更改支持库版本以便可以使用新的SwipeToRefreshLayout来:

dependencies {
    compile 'com.android.support:support-v4:21.0.2'
}
然后我的文本视图没有应用Robot瘦字体,文本是粗体的


怎么会这样?我认为问题只在于Roboto Thin,因为其他具有Roboto Regular的文本视图工作正常。有什么想法吗?

创建一个自定义的TextView类

public class CustomTextView extends TextView {

public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
}

public CustomTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

public CustomTextView(Context context) {
    super(context);
    init();
}

public void init() {
    if (!isInEditMode()) {
        Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/Roboto-Thin.ttf");
        setTypeface(tf, 1);
    }


}

public void setNewText(CharSequence text) {
    // code to check text for null omitted
    super.setText(text, BufferType.SPANNABLE);

}
}
在这之后,改变你的想法

<TextView

是解决这个错误的更好方法吗

<TextView
<CustomTextView