2017-03-08 65 views
0

我正在使用反应原生矢量图标来显示工具栏上的操作图标。但它似乎并不奏效。反应原生ToolbarAndroid操作图标不起作用

进口&图标

import Icon from 'react-native-vector-icons/FontAwesome'; 
const myIcon = (<Icon name="compass" size={30} color="#900" />) 

主要观点

<View style={styles.containerToolbar}> 
    <ToolbarAndroid style={styles.toolbar} 
     title="Test" 
     actions={toolbarActions} 
     onActionSelected={this.onActionSelected}> 
    </ToolbarAndroid> 
</View> 

var toolbarActions = [ 
    {title: 'Compass', icon:{myIcon} show: 'always'} 
]; 
+0

哪里是你的onActionSelected方法? –

+0

为什么这很重要? – Coder

回答

0

您可以设置的操作图标这样的 -

var toolbarActions = [ 
    {title:'Compass', iconName:'compass', iconColor:"#900", iconSize:30, show:'always'} 
]; 

而且你需要使用Icon.ToolbarAndroid,而不是ToolbarAndroid

<Icon.ToolbarAndroid 
    actions={toolbarActions} 
    .... 
> 

更多细节在这里 - https://github.com/oblador/react-native-vector-icons#usage-with-toolbarandroid

+0

不要以为你仔细阅读这个问题。我正在尝试设置图标,而不是navIcon – Coder

+0

更新了我的答案 – vinayr