Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android:Crouton lib和自定义字体大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的应用程序中使用自定义字体,所以我想要一个Crouton的自定义字体.我试过用setTextAppearance做它,它不起作用.

<?xml version="1.0" encoding="utf-8"?>
<com.ecab.ui.custom.TextViewCustomFont
    xmlns:android="http://scheR_530_11845@as.android.com/apk/res/android"
    xmlns:custom="http://scheR_530_11845@as.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

解决方法

好的,我发现了问题

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

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和自定义字体所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。