reactjs - 如何在 TabBar 中添加图标 (createMaterialTopTabNavigator) ReactNative
问题描述
嗨,我是 React Native 的新手,我正在使用 TabBar createMaterialTopTabNavigator ,现在我想在标签中本地添加图标 我的代码是
const TabScreen = createMaterialTopTabNavigator(
{
Home: { screen: Home },
Settings: { screen: Settings }
});
我有两个类名称 Home 和 Settings 也是我的标签样式代码
{
tabBarPosition: 'top',
swipeEnabled: true,
animationEnabled: true,
tabBarOptions: {
activeTintColor: '#FFFFFF',
inactiveTintColor: '#F8F8F8',
style: {
backgroundColor: '#633689',
},
labelStyle: {
textAlign: 'center',
},
indicatorStyle: {
borderBottomColor: '#87B56A',
borderBottomWidth: 2,
},
},}
解决方案
您必须在选项卡屏幕中添加带有 TabBarIcon 的导航选项,
Home: {
screen: Home,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
//Your icon component for example =>
<Icon name="home" size={30} color="#900" />
)
},
},
并在 tabBarOptions 中添加 showIcon: true,
{
tabBarPosition: 'top',
swipeEnabled: true,
animationEnabled: true,
tabBarOptions: {
showIcon: true,
activeTintColor: '#FFFFFF',
inactiveTintColor: '#F8F8F8',
style: {
backgroundColor: '#633689',
},
labelStyle: {
textAlign: 'center',
},
indicatorStyle: {
borderBottomColor: '#87B56A',
borderBottomWidth: 2,
},
},}
推荐阅读
- angular - 无法绑定到“formGroup”,因为它不是 Angular 中“form”的已知属性
- symfony - 是否可以自定义子资源api平台?
- c++ - 如何在 C++ 文本文件的行尾添加数据?
- python-3.x - 从所有子目录中读取内容
- bash - 将文本文件中的所有数字缩写转换为数值
- c# - 在 XML 文档注释中引用通用类型
- node.js - ResolveJS 后端系统的生产部署/运行时架构是什么?
- java - 我在springboot的帖子正文中发送请求它不起作用
- react-native - React Native iOS 构建成功,但未显示图像和徽标
- reactjs - 如何使用 TypeScript 和 Next.js 将整个道具传递给子组件?