简体   繁体   English

反应原生:设置标签导航 5 样式的方法是什么?

[英]react native: what is the way to style the tabs navigation 5?

i am use navigation 5 and i wanna style my tab navigator what is the way to :我正在使用导航 5,我想为我的标签导航器设置样式:

1.Create a view over the tabs ? 1.在选项卡上创建视图? 2. color the tabs and color the background of them ? 2. 给标签上色并给它们的背景上色?

const Tab = createMaterialTopTabNavigator();

export default function Screen8() {
  const navigation = useNavigation();
  const route = useRoute();
  const params = route.params;
  const { item } = params;
  console.log('screen 8: ', params);
  return (
    <Tab.Navigator>
      <Tab.Screen name="frog" component={NetuneyDigum} />
      <Tab.Screen name="bomb" component={BdikotSadea} />
      <Tab.Screen name="zibi" component={E_BitsuaDigdum} />
    </Tab.Navigator>
  );
}

In your Tab.Navigator

<Tab.Navigator
        screenOptions={({ route }) => ({
          tabBarIcon: ({ focused, color, size }) => {
            let iconName;

            if (route.name === 'Home') {
              iconName = focused
                ? 'ios-information-circle'
                : 'ios-information-circle-outline';
            } else if (route.name === 'Settings') {
              iconName = focused ? 'ios-list-box' : 'ios-list';
            }

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

More info in the docs https://reactnavigation.org/docs/tab-based-navigation文档中的更多信息https://reactnavigation.org/docs/tab-based-navigation

Just figured out the solution for this as the docs didn't work for me.只是想出了解决方案,因为文档对我不起作用。 You have to add the tabBarOptions attribute to Tab.Navigator then put your styles in there.您必须将 tabBarOptions 属性添加到 Tab.Navigator 然后将您的样式放在那里。 I included how to add icons as well in case you need that, but if you don't need it just remove that我还包括了如何添加图标,以防您需要它,但如果您不需要它,只需删除它

const Tab = createBottomTabNavigator()
const TabNavigator = () => {
    return(
        <Tab.Navigator
            tabBarOptions={{ 
                activeTintColor: '#D82A93',
                labelStyle: {
                    fontSize: 12,
                },
                style: {
                    height: 84,
                },
                tabStyle: {
                    height: 60,
                },
            }}
            screenOptions={({ route }) => ({
                tabBarIcon: ({ focused, color, size }) => {
                    let iconName;
                    let type='material-community'
                    if (route.name === 'Home') {
                        iconName = 'home-outline'
                    } else if (route.name === 'Grow') {
                        iconName = 'flower-outline'
                    } else if (route.name === 'Events') {
                        iconName = 'calendar-clock'
                    } else if (route.name === 'Discussion') {
                        iconName = 'comment-discussion'
                        type = 'octicon'
                    } else {
                        iconName = 'flag-variant-outline'
                    }
                    return <Icon type={type} name={iconName} size={35} color={color}  />;
                },
            })}
        >
            <Tab.Screen name='Home' component={StackNavigator} />
            <Tab.Screen name="Grow" component={Grow} options={{headerShown: false}} />
            <Tab.Screen name="Events" component={SettingsScreen} options={{headerShown: false}} />
            <Tab.Screen name="Discussion" component={SettingsScreen} options={{headerShown: false}} />
            <Tab.Screen name="Progress" component={SettingsScreen} options={{headerShown: false}} />
        </Tab.Navigator>
    )
}

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

相关问题 反应原生:标签导航风格 - react native : tab navigation style 使用标签来响应本机导航注销功能 - React Native Navigation Log Out functionality with tabs react native:改变 TOAST 风格的正确方法是什么? - react native : What is the right way to change a TOAST style? tabBarOnPress在react-native中的react导航选项卡中不起作用 - tabBarOnPress not working in react navigation tabs in react-native React Native Navigation v5 从底部选项卡触发抽屉 - React Native Navigation v5 triggering a drawer from bottom tabs 什么是最佳实践导航反应原生 - what's the best practice navigation react native React native:使用 react-navigation、react-navigation-tabs 和 react-navigation-stack 时的不变违规 - React native: invariant violation when using react-navigation, react-navigation-tabs & react-navigation-stack react native演示中的哪种代码风格? - what code style in react native demo ? React Native:当在子组件上使用spread运算符时,将样式作为props传递的正确方法是什么 - React Native: what is a proper way to pass style as props, when using spread operator on the child component 在React-Native中使用按钮按下从抽屉导航屏幕到抽屉导航屏幕的方法是什么? - What is the way to go from Drawer Navigation Screen to a Screen out of Drawer navigation using button press in React-Native?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM