【问题标题】:Red square rendering instead of the AwesomeFont Icon红色方形渲染而不是 AwesomeFont 图标
【发布时间】:2016-08-07 10:03:45
【问题描述】:

我正在关注这个 github:https://github.com/corymsmith/react-native-icons 来学习如何在我的应用程序上放置一些图标!所以我照他们说的做了:

-包含在android/setting.gradleandroid/app/build.gradle代码的不同部分。

-做register module (in MainActivity.java),在我对应的MainActivity.Java中导入

-Copy the font files and .json 在我刚刚创建的目录资产中...

在我的 MainActivity.java 中粘贴 onCreate 和引用 .addPackage(new ReactNativeIcons(Arrays.asList( new IconFont("typicons", "typicons.ttf")

我的电话也是<Icon name='typicons|beer' size={150} color='#887700' style={styles.beer}/>

这种风格

beer: { width: 50, height: 50, margin: 5, color: '#887700' },

但我的应用程序在这个位置只显示一个红色方块。只是边框是红色的,里面是白色的……我没有错误。所以我忘记了什么吗? 如果您有任何想法可以帮助我! :) 这很奇怪:/

谢谢!

【问题讨论】:

  • 据我所知,该库不再维护。我试图在我的项目中使用它们,我遇到了同样的问题。当我四处寻找答案时,我读到 react-native-icons 不再维护,所以我开始使用 react-native-vector-icons github.com/oblador/react-native-vector-icons 并且我对它们没有任何问题(目前): )
  • 我刚看到,这可能是原因...:/悲伤!是的,我现在正在寻找 react-native-vector-icons ,我尝试使用它!而且它看起来并不比 react-native-icon 更难......所以我们会看到:) 谢谢你的回答!
  • @Vikky 我们同意,我只需要做npm install react-native-icons@latest --save 并将字体的内容复制到 app/src/main/assets/fonts 。例如使用它:var Icon = require('react-native-vector-icons/FontAwesome')然后&lt;Icon.Button name="facebook" backgroundColor="#3b5998" onPress={this.loginWithFacebook}&gt; Login with Facebook &lt;/Icon.Button&gt; ....

    因为这不起作用...:/

  • 你必须做npm install react-native-vector-icons --save,然后rnpm link +我还必须将Fonts文件夹中的内容复制到android/app/src/main/assets/fonts(注意小写字体文件夹)。然后我像这样使用它 var Icon = require('react-native-vector-icons/FontAwesome'); var myIcon = (&lt;Icon name="rocket" size={30} color="#900" /&gt;) 和 ofc 在渲染器内部用 {myIcon} 调用它。我试过 Icon.Button 它对我有用,我会在下一条评论中粘贴你的代码
  • 短版代码:import Icon from "react-native-vector-icons/FontAwesome"; const myIcon = (&lt;Icon name="pencil-square-o" size={18} color="#F5FCFF"/&gt;); class Navbar extends Component { render() { var myButton = ( &lt;Icon.Button name="facebook" backgroundColor="#3b5998" onPress={this.loginWithFacebook}&gt; Login with Facebook &lt;/Icon.Button&gt; ); return ( &lt;View&gt; &lt;Text&gt;{myIcon} To Do&lt;/Text&gt;{myButton} &lt;/View&gt; ); } } export default Navbar;

标签: reactjs react-native font-awesome


【解决方案1】:

我是 react-native 框架的新手...而且我不知道我将不得不做 "react-native run-android" 。我以为做“rnpm link”...和“reload JS”会更新新的node_module....

所以我用“react-native run-android”重新安装了我的应用程序,它接受了新的 node_module 参数......它现在可以工作了!谢谢@Vikky!下次我会知道的:p

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多