首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在“反应导航4”中显示选项卡栏图标

如何在“反应导航4”中显示选项卡栏图标
EN

Stack Overflow用户
提问于 2020-10-19 07:00:21
回答 1查看 2.6K关注 0票数 2

我想显示底部标签焦油在反应导航4,但没有运气使它发生,甚至我使用它。有人能帮我找出我的代码的问题或者我应该使用哪个选项吗?

代码语言:javascript
复制
static navigationOptions = {
    title: "Map",
    tabBarIcon: ({ tintColor }) => {
      return <Icon name="home" size={30} color={tintColor} />;
    }
}

在任何组件屏幕中,它仍然不能工作。

这里是我的路由器

我想将下面的选项卡图标应用到主屏幕上

代码语言:javascript
复制
const MainAuthenticated = createAppContainer(
  createBottomTabNavigator(
    {
      main: {
        screen: createBottomTabNavigator({
          Marketplace: {
            screen: createStackNavigator({
              home: {
                screen: HomeScreen,
              },
              profile: { screen: Profile },
              business: { screen: MyBusiness },

              logout: { screen: Logout },

              itemlist: { screen: ItemList },
              itemcreate: { screen: ItemCreate },
              itemdetail: { screen: ItemDetail },
              businesscreate: { screen: BusinessCreate },
              businessdetail: { screen: MyBusinessDetail },
            }),
          },
          XOrders: { screen: OrderScreen },
          Favorite: { screen: FavoriteScreen },
        }),
      },
    },
    {
      defaultNavigationOptions: {
        tabBarVisible: false,
      },
    },
  ),
);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-19 07:32:07

下面是在react-navigation v4中添加底部选项卡条图标的工作代码

代码语言:javascript
复制
import Ionicons from 'react-native-vector-icons/Ionicons';
import { createAppContainer } from 'react-navigation';
import { createBottomTabNavigator } from 'react-navigation-tabs';

export default createBottomTabNavigator(
  {
    Home: HomeScreen,
    Settings: SettingsScreen,
  },
  {
    defaultNavigationOptions: ({ navigation }) => ({
      tabBarIcon: ({ focused, horizontal, tintColor }) => {
        const { routeName } = navigation.state;
        let IconComponent = Ionicons;
        let iconName;
        if (routeName === 'Home') {
          iconName = focused
            ? 'ios-information-circle'
            : 'ios-information-circle-outline';
          // Sometimes we want to add badges to some icons.
          // You can check the implementation below.
          IconComponent = HomeIconWithBadge;
        } else if (routeName === 'Settings') {
          iconName = focused ? 'ios-list-box' : 'ios-list';
        }

        // You can return any component that you like here!
        return <IconComponent name={iconName} size={25} color={tintColor} />;
      },
    }),
    tabBarOptions: {
      activeTintColor: 'tomato',
      inactiveTintColor: 'gray',
    },
  }
);

如果您想要使用一些.pngjpeg或其他图像文件,而不是矢量图标,只需替换

代码语言:javascript
复制
<IconComponent name={iconName} size={25} color={tintColor} /> // replace this with below

<Image source={require('your image path')} style={{height: 30, width: 30}} />
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64422533

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档