Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:Crouton库和自定义字体_Android_Crouton - Fatal编程技术网

Android:Crouton库和自定义字体

Android:Crouton库和自定义字体,android,crouton,Android,Crouton,我在我的应用程序中使用自定义字体,所以我想为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.

我在我的应用程序中使用自定义字体,所以我想为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" />
然后,我尝试用我的字体更改setTypeface(),但它不起作用

<?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();
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

可以创建使用文本资源ID的自定义样式 通过Style.Builder.setTextAppearance(…)显示外观

这将从styles.xml中获取一个引用,并在 克劳顿的内部文本视图

然后,您可以使用 自定义样式


MyFonts.getGothamBookBold()看起来怎么样

然而,这应该是可行的:

  private TextView initializeTextView(final Resources resources) {
    TextView text = new TextView(this.activity);
    text.setId(TEXT_ID);
    text.setText(this.text);
    Typeface myTypeFace = Typeface.createFromAsset(this.activity.getAssets(), "gothamBold.ttf"); 
    text.setTypeface(myTypeFace);
    text.setGravity(this.style.gravity);

    // set the text color if set
    if (this.style.textColorResourceId != 0) {
      text.setTextColor(resources.getColor(this.style.textColorResourceId));
    }

好吧,我发现问题了

它通过改变字体与第二种解决方案协同工作。我刚忘了取下那根绳子

setTextAppearance(R.id.crouton)
在时尚课上。因此,我的自定义样式如下:

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

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

可能会有所帮助。您是否尝试过创建者在此处提出的建议:是的!我知道这个问题,但它不起作用…可能是@aat的重复。您如何编辑cruton.class文件?它被锁定在build/intermediates/exploded aar/de key..../cruton/1.8.5/classes.jar我有一个类来管理我的自定义字体,如下所示:
public static Typeface getgothamboolbold(Context ctx){return Typeface.createfromset(ctx.getAssets(),BASE+“Gotham Bold.otf”);}
您如何编辑cruton.class文件?它被锁定在build/intermediates/aar/de key..../cruton/1.8.5/classes中。jar@ono我不确定我是否理解你的问题。我没有编辑Crouton源代码。@Ahmad,你不是在编辑Crouton.class中的
initializeTextView
方法吗?@ono啊,对不起。我没有看问题的背景。我两年前就回答了这个问题,不记得OP要求定制一个版本的Cruston。基本上,您必须,而不是通过gradle将Crouton添加为依赖项,而是将其添加为模块并自己修改源代码。我刚刚检查了一下,看起来Crouton仍然不支持自定义字体,所以这是可能的解决方案之一。可能是最直接的一个。