如何更改CardInputWidget(Stripe)的fontFamily

时间:2018-02-14 04:30:55

标签: android stripe-payments android-styles android-fonts

我试图以CardInputWidget为主题来匹配我应用的其余部分,但我似乎无法将android:fontFamily="@font/font_name"项直接应用于视图或使用样式或主题。< / p>

这是com.stripe:stripe-android:5.1.0

2 个答案:

答案 0 :(得分:1)

从我的实验中,通过android:fontFamily属性中使用的样式设置android:theme不起作用。

但是,我可以使用此方法在CardInputWidget中搜索所有TextView子项并在运行时更改其字体:

public static void setTypeface(Typeface tf, View v) {
    if (v instanceof TextView) {
        ((TextView) v).setTypeface(tf);
    }
    else if (v instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) v;

        for (int i = 0; i < vg.getChildCount(); i++) {
            setTypeface(tf, vg.getChildAt(i));
        }
    }
}

调用它非常简单:

Typeface tf = Typeface.create("sans-serif-medium", Typeface.NORMAL);
CardInputWidget card = findViewById(R.id.card);

setTypeface(tf, card);

答案 1 :(得分:0)

您可以将主题属性主题用于自定义字体。我在下面给出了代码捕捉

  // use this in card
         <com.stripe.android.view.CardInputWidget
            android:id="@+id/card_input_widget"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/textRegular"      <---- use this
              />


 <style name="textRegular" parent="android:Widget.TextView">
    <item name="android:fontFamily">@font/poppins_regular</item>
</style>
相关问题