【发布时间】:2019-06-04 13:35:55
【问题描述】:
我使用来自https://reactnavigation.org/docs/en/bottom-tab-navigator.html 的createBottomTabNavigator 在本机反应中创建了一个导航器
我遇到的问题是我找不到在标签栏中垂直居中标签的方法。
正如您在screenshot 中看到的那样,标签底部总是有那个蓝色区域。即使我手动设置选项卡的高度,它们也会向上增长。如果我为标签栏设置flex:1,它会占据屏幕的一半,但蓝色区域仍然存在。
tabBar: {
backgroundColor: 'blue',
borderWidth: 2,
height: 32,
justifyContent: 'center',
alignItems: 'center',
padding: 0
},
labelStyle: {
backgroundColor: 'green',
},
tabStyle: {
backgroundColor: 'yellow',
flex: 1,
justifyContent: 'center',
alignItems: 'center',
alignSelf: 'center',
borderWidth: 1,
borderColor: 'black',
marginBottom: 0,
paddingBottom: 0,
},
这就是我创建导航栏的方式(为简单起见,我删除了图标):
const TabNavigator = createBottomTabNavigator(
{
screen1: { screen: screen1 },
screen2: { screen: screen2 },
screen3: { screen: screen3 },
screen4: { screen: screen4 },
},
{
tabBarOptions: {
style: styles.tabBar,
labelStyle: styles.labelStyle,
tabStyle: styles.tabStyle
},
}
);
const App = createAppContainer(TabNavigator);
export default () => {
return (
<SafeAreaView style={{ flex: 1, backgroundColor: 'red' }}>
<App />
</SafeAreaView>
);
};
【问题讨论】:
标签: javascript react-native flexbox react-navigation tabnavigator