我在我的应用程序中使用自定义字体,所以我想要 Crouton 的自定义字体。我试过用 setTextAppearance 来做,它不起作用。
<?xml version="1.0" encoding="utf-8"?>
<com.ecab.ui.custom.TextViewCustomFont
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/com.crouton"
android:id="@+id/crouton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ban_confirmation"
android:gravity="center"
android:text="TEST"
android:textColor="@android:color/white"
custom:typeface="gothamBold" />
在样式类中:
INFOCUSTOM = new Builder().setDuration(3000).setTextAppearance(R.id.crouton).build();
然后,我尝试通过用我的字体更改 setTypeface() 来做到这一点,但它不起作用。
在面包块类:
private TextView initializeTextView(final Resources resources) {
TextView text = new TextView(this.activity);
text.setId(TEXT_ID);
text.setText(this.text);
text.setTypeface(MyFonts.getGothamBookBold(this.activity));
Log.d(Constants.D_TAG, "chaneg the typeFace");
text.setGravity(this.style.gravity);
// set the text color if set
if (this.style.textColorResourceId != 0) {
text.setTextColor(resources.getColor(this.style.textColorResourceId));
}
// Set the text size. If the user has set a text size and text
// appearance, the text size in the text appearance
// will override this.
if (this.style.textSize != 0) {
text.setTextSize(TypedValue.COMPLEX_UNIT_SP, this.style.textSize);
}
// Setup the shadow if requested
if (this.style.textShadowColorResId != 0) {
initializeTextViewShadow(resources, text);
}
// Set the text appearance
if (this.style.textAppearanceResId != 0) {
text.setTextAppearance(this.activity, this.style.textAppearanceResId);
}
return text;
}
我该怎么做才能拥有自定义字体?
ps:库版本==> 1.7