gpt4 book ai didi

安卓 : Crouton lib and custom font

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:03:40 24 4
gpt4 key购买 nike

我在我的应用程序中使用自定义字体,所以我想要一个用于面包丁的自定义字体。我已经尝试使用 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() 来做到这一点,但它不起作用。

在 Crouton 类中:

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

最佳答案

好的,我找到问题了!

它通过更改字体与第二种解决方案一起使用。我刚刚忘记删除

setTextAppearance(R.id.crouton)

在样式类中。所以我的自定义样式是这样的:

INFOCUSTOM = new Builder().setDuration(3000).setBackgroundDrawable(R.drawable.ban_confirmation).setHeight(LayoutParams.WRAP_CONTENT)
.build();

一个问题解决了,另一个问题来了:)!使用背景可绘制,文本不是垂直居中

关于安卓 : Crouton lib and custom font,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16124870/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com