0

我很难让自定义 webfonts 在 android 上与 react-native 一起使用。

我已按照此处的说明https://medium.com/@gattermeier/custom-fonts-in-react-native-for-android-b8a331a7d2a7#.w6aok6lpw但没有成功。

我尝试了几种不同的字体,仍然没有乐趣。

nb我试过重命名字体文件,用下划线替换破折号,全部小写等等,但仍然没有成功。

任何帮助,非常感谢。这是我的代码:

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
} from 'react-native';

class MyBeltingApp extends Component {
  render() {
    return (
      <View>
        <Text style={styles.welcome}>
         Straigtline
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  welcome: {
    fontFamily: 'GT-Walsheim-Bold',
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
});

AppRegistry.registerComponent('MyBeltingApp', () => MyBeltingApp);
4

1 回答 1

2

我已经设法让字体工作了。

在我的项目的根目录中创建了一个字体文件夹。

然后在 package.json

  "rnpm": {
    "assets": ["fonts"]
  }

然后运行rnpm link assets

嘘……

注意。我不必更改任何文件名或任何东西。他们可以很好地使用破折号。

于 2016-08-17T15:28:01.080 回答