Android:Crouton lib和自定义字体

Android:Crouton lib和自定义字体,第1张

概述我在我的应用程序中使用自定义字体,所以我想要一个Crouton的自定义字体.我试过用setTextAppearance做它,它不起作用. <?xml version="1.0" encoding="utf-8"?><com.ecab.ui.custom.TextViewCustomFont xmlns:android="http://schemas.android.com/apk/res 我在我的应用程序中使用自定义字体,所以我想要一个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" />

在Style类中:

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

解决方法 好的,我发现了问题!

它通过@R_584_6502@与第二种解决方案一起使用.我忘记了删除

setTextAppearance(R.ID.crouton)

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

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

一个问题解决了,另一个问题到了:)!在背景可绘制的情况下,文本不是垂直居中的

总结

以上是内存溢出为你收集整理的Android:Crouton lib和自定义字体全部内容,希望文章能够帮你解决Android:Crouton lib和自定义字体所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1127442.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存