react-native - 如何居中对齐 createMaterialTopTabNavigator
问题描述
目前我的项目都在左边,因为它们应该是默认的。我似乎无法将其移至中心。作为参考,我附上了一张图片
https://i.stack.imgur.com/lZ2Eu.png
我已经尝试使用 tabStyle 设置样式并使用 alignSelf: 'center' alignItems: 'center' flexDirection: 'row', justifyContent: 'center'
这是代码:
export const FoodScreenNavigator = createMaterialTopTabNavigator(
{
"McD": {
screen: McDGrid,
navigationOptions: {
tabBarLabel: "McD"
}
},
"Subway": {
screen: SubwayScreen,
navigationOptions: {
tabBarLabel: "Subway"
}
},
"BurgerKings": {
screen: BurgerKingSelection,
navigationOptions: {
tabBarLabel: "Burger Kings"
}
},
"ItalianMCT": {
screen: StyleSelection,
navigationOptions: {
tabBarLabel: "Italian MCT"
}
}
},
{
tabBarOptions: {
activeTintColor: colors.FontColors.light_grey,
inactiveTintColor: colors.FontColors.light_grey,
style: {
backgroundColor: colors.FontColors.dark_grey,
justifyContent: "center"
},
labelStyle: {
textAlign: "center",
fontSize: fonts.h5,
fontFamily: fonts.OpenSansSemiBold,
justifyContent: "center"
},
tabStyle:{
width: "auto"
},
indicatorStyle: {
borderBottomColor: colors.UiBgColors.light_red,
borderBottomWidth: 4,
justifyContent: "center"
},
upperCaseLabel: false
},
backBehavior: "none"
}
);
包.json
"react-navigation": "^4.0.8",
"react-navigation-drawer": "^2.2.2",
"react-navigation-stack": "^1.9.0",
"react-navigation-tabs": "^2.5.6",
解决方案
尝试以标签样式添加marginLeft,例如
tabStyle:{
width:"auto",
marginLeft:3,
},
推荐阅读
- javascript - 如何使用 React useRef 挂钩删除地图中的类
- apache-spark - Spark Streaming:通过接收到的流键从 HBase 读取?
- python - 如何在 Python 中删除列表中的重复元素
- python - 如何将接收到的(承载)访问令牌传递给生成的 REST 客户端,以调用安全的 API-Gateway 端点
- python - Python - datetime.time() 比较将 AttributeError 作为“str”对象返回
- reactjs - 如何使用 Recoil 在 React 组件之外操作全局状态?
- python - 获取 xgboost 线性模型的系数
- r - 如何融化具有多个组和空后缀的data.frame
- angular - Angular - 如何在按钮中添加金额?
- javascript - 如何根据参数插入键并在对象 es6 中更新其值