2016-03-17 57 views
2

我已經複製從陣營本地的UIExplorer爲AndroidToolBar代碼:!React Native Android - 如何在ToolBarAndroid中設置標誌圖標?

<ToolbarAndroid 
      logo={require('image!launcher_icon')} 
      navIcon={require('image!ic_menu_black_24dp')} 
      onIconClicked={() => this.drawer.openDrawer()} 
      style={styles.toolbar} 
      title={title} 
      /> 

但它似乎像圖像launcher_icon圖像ic_menu_black_24d p的缺失。我得到一個缺少的錯誤:
enter image description here

這似乎是一些系統的烘烤圖標。

  1. 如何使用此圖標?
  2. 如何使用我自己的PNG文件?

回答

4

這是舊的語法。它在最近的版本中已被更改。

<ToolbarAndroid 
    logo={require('./ic_launcher_icon.png')} 
    navIcon={require('./ic_menu_black.png')} 
    onIconClicked={() => this.drawer.openDrawer()} 
    style={styles.toolbar} 
    title={title} 
/> 

看看這個指南https://facebook.github.io/react-native/docs/images.html#content https://facebook.github.io/react-native/docs/image.html#content

+0

所以我需要手動添加ic_launcher_icon.png作爲文件到我的文件夾樹? –

+0

是的。以前,您必須將其添加到xcode或android studio中。現在您可以將其添加到文件樹中。您也可以使用不同的分辨率後綴2x,3x等。查看本指南https://facebook.github.io/react-native/docs/images.html#content –

+0

謝謝!幫了我很多! –

0

嘗試使用更新的語法和定義圖像資源的正確路徑,我已經取得了「圖像」內部「應用程序」文件夾到我的所有圖像保存在一個地方。你可以跳過它們。

<ToolbarAndroid style ={{height:56, backgroundColor:'#e0e0e0'}} 
       logo={require('./app/images/jd_home.png')} 
       title={"MyApp"} 
       actions={[{title: 'More', icon: require('./app/images/more.png'), show: 'always'}, 
         {title: 'Settings', icon: require('./app/images/settings.png'), show: 'always'}]} 
       /> 
相關問題