[英]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.