简体   繁体   English

用MaterialCommunityIcons中的图标替换react-native-paper搜索栏中的搜索图标

[英]Replace search icon in react-native-paper searchbar with icons from MaterialCommunityIcons

I want to change the search icon in the searchbar of react-native-paper with the barcode-scan icon. 我想更改搜索图标搜索栏反应原生纸与条形码扫描图标。
The native-paper uses react-native-vector-icons for icons and barcode-scan available in MaterialCommunityIcons 本机纸使用react-native-vector-icons进行图标处理并在MaterialCommunityIcons中使用条形码扫描
Here is the code that I tried which gives a blank instead of an icon 这是我尝试的代码,该代码给出了空白而不是图标

import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons';
<Searchbar
  placeholder="Search"
  onChangeText={query => { this.setState({ firstQuery: query }); }}
  value={firstQuery}
  icon={<MaterialCommunityIcon name="barcode-scan" size={30}/>}
/>

Is this the right way or am I missing something? 这是正确的方法还是我错过了什么?

在此处输入图片说明

您必须使用回调来传递图标prop中的组件

icon={() => <MaterialCommunityIcons name="barcode-scan" size={30}/>}

Just adding '()=>' in icon wiil be suffice 只需在图标中添加'()=>'就足够了

 import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons'; <Searchbar placeholder="Search" onChangeText={query => { this.setState({ firstQuery: query }); }} value={firstQuery} icon={()=><MaterialCommunityIcon name="barcode-scan" size={30}/>} /> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 react native:Searchbar的背景(react-native-paper) - react native: background of Searchbar (react-native-paper) 有没有办法在 react-native-paper SearchBar 中获取键盘搜索/返回输入? - Is there a way to grab the keyboard search/return input in react-native-paper SearchBar? 使用自定义 fonts 和,按钮使用 react-native-paper - Using custom fonts and, button with icons using react-native-paper 如何在 react-native-paper 中使图标旋转? - How to make icon spin in react-native-paper? React-native 与故事书问题 react-native-vector-icons 和 react-native-paper - React-native with storybook problem react-native-vector-icons and react-native-paper 在 react-native-paper 中,如何删除搜索栏和菜单之间的空间 - In react-native-paper, how can I remove the space between the searchbar and the menu React Native - MaterialCommunityIcons typescript 定义图标名称 - React Native - MaterialCommunityIcons typescript definition for icon name 当用户在 react-native-paper 搜索栏输入之外单击时隐藏键盘并失去焦点 - Hide keyboard and lose focus when user click outside the react-native-paper searchbar input react-native-paper DataTable 文本样式 - react-native-paper DataTable text style 如何在没有按钮组件的 react-native-paper 中获取图标组件,如 react-native-elements - How to get an Icon Component in react-native-paper without Button Component like in react-native-elements
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM