【问题标题】:react-native picker using android styles.xml for change font-family not changedreact-native 选择器使用 android styles.xml 更改字体系列未更改
【发布时间】:2017-10-11 03:15:24
【问题描述】:

我想要 react-native 选择器上的样式字体大小和字体系列。我已经在原生 android 上设置了自定义样式。但是在我再次构建 apk 之后,它仍然是相同的字体。

我在 style.xml 上的代码

<resources>
 <!-- Base application theme. -->
 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
     <!-- Customize your theme here. -->
     <item name="android:spinnerItemStyle">@style/SpinnerItem</item>
 </style>
 <style name="SpinnerItem" parent="Theme.AppCompat.Light.NoActionBar">>
   <item name="android:fontFamily">CenturyGothicBold</item>
   <item name="android:textSize">16dp</item>
 </style>
</resources>

Already set add new font on asset with react-native link

My result

【问题讨论】:

  • 你找到解决办法了吗?

标签: android react-native react-native-android


【解决方案1】:

试试下面的代码:

 TextView tx = (TextView)findViewById(R.id.textview1);

   Typeface custom_font = Typeface.createFromAsset(getAssets(),  "fonts/CenturyGothicBold.ttf");

   tx.setTypeface(custom_font);

或者

 AssetManager am = context.getApplicationContext().getAssets();

    typeface = Typeface.createFromAsset(am,
            String.format(Locale.US, "fonts/%s", "CenturyGothicBold.ttf"));

    setTypeface(typeface);

【讨论】:

    猜你喜欢
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-01
    • 2014-09-22
    相关资源
    最近更新 更多