你如何使用React-native android自定义字体? [英] How do you use custom fonts with React-native android?

查看:460
本文介绍了你如何使用React-native android自定义字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经按照这里的指示 https://medium.com/@gattermeier/custom-fonts-in-反应本机为Android的b8a331a7d2a7#.w6aok6lpw ,但没有成功。

我已经尝试了一些不同的字体,仍然没有喜悦。



nb 我尝试重新命名字体文件,用下划线代替破折号,全部小写,但仍然没有成功。 / p>

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

 从'react'导入React,{Component}; 
从'react-native'导入{
AppRegistry,
StyleSheet,
Text,
View,
};

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


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

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


解决方案

我已经设法使字体工作。 / p>

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



然后在package.json中

 rnpm:{
assets:[fonts]
}

然后运行 rnpm链接资产



huzzah ...

nb。我不必更改任何文件名或任何东西。他们使用破折号很好。


I'm having difficulty getting custom webfonts to work with react-native on android.

I have followed the instructions from here https://medium.com/@gattermeier/custom-fonts-in-react-native-for-android-b8a331a7d2a7#.w6aok6lpw but to no success.

I've tried with a few different fonts, still no joy.

nb I've tried renaming the font files, replaces dashes with underscores, all lowercase, and so on, but still no success.

Any help, greatly appreciated. This is my code:

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

解决方案

I've managed to get the fonts working.

Created a fonts folder in the root of my project.

then in package.json

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

then run rnpm link assets

huzzah...

nb. I didn't have to change any files names or anything. they work with dashes just fine.

这篇关于你如何使用React-native android自定义字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆