如何更改createMaterialBottomTabNavigator标签样式(react-native)?

Ali*_*aXX 5 react-native react-navigation

createMaterialBottomTabNavigator是一个非常好的解决方案,用于在 上添加 BottomTabNavigation react-native,但我还没有找到一种方法来设置其标签的样式,这可能吗?

MET*_*EAD 8

(react-navigation-material-bottom-tabs) 的官方文档没有提供任何用于设置标签样式的内容,但您可以按如下方式设置它们的样式:

navigationOptions: {
    tabBarLabel: <Text style={{fontFamily : "pacifico", textAlign : "center"}}>Meals</Text>,
    tabBarIcon: (tabInfo) => {
        return (<MaterialCommunityIcons name="food-fork-drink" size={23}
            color={tabInfo.tintColor}></MaterialCommunityIcons>)
    },
    tabBarColor: "#222f3e"
}
Run Code Online (Sandbox Code Playgroud)

tabBarLabel通过将其包装在组件中,直接将样式应用于Text

  • 这不适用于反应导航 5,但适用于反应导航 4。 (2认同)

Has*_*tha 5

React Navigation V6,你可以试试这个。

<Tab.Screen
    name="Home"
    component={Home}
    options={{
      tabBarLabel: <Text style={styles.tabBarLabel}>Home</Text>
    }}
/>

// Stylesheet

const styles = StyleSheet.create({
  tabBarLabel: {
    fontSize: 12,
    color: Colors.darkGreen,
    textAlign: 'center',
    fontFamily: 'Poppins',
    fontWeight: 'bold',
  },
});
Run Code Online (Sandbox Code Playgroud)

  • 我不明白为什么他们将其类型指定为字符串(tabBarLabel 类型),而它也可以与 Elements 配合使用。 (4认同)