我刚开始用 react-native 开发一个应用程序,并添加了一个底部导航。然后我开始为组件设置样式,并注意到导航上方有一条白线,我无法摆脱它。
问题图片
任何有关如何使该线与背景颜色相同的想法将不胜感激。视图背后的默认背景颜色可能是“透光”,因为它是白色的,我不知道如何更改它。该应用程序只能在我自己的 iPhone XR 上运行,所以我不担心与 android 或其他 iPhone 型号的兼容性
我是一个关于 react-native 的完整初学者,所以请耐心等待。到目前为止,这是我的代码:
导航
const Tab = createBottomTabNavigator();
export default function App() {
return (
<NavigationContainer>
<Tab.Navigator
tabBarOptions={{
activeTintColor: Colors.tabIconSelected,
inactiveTintColor: Colors.tabIconDefault,
style: styles.container
}}>
<Tab.Screen
name="Payments"
component={PaymentScreen}
options={{
tabBarIcon: ({focused}) => <TabBarIcon focused={focused} name="logout"/>
}}/>
<Tab.Screen
name="Income"
component={IncomeScreen}
options={{
tabBarIcon: ({focused}) => <TabBarIcon focused={focused} name="login"/>
}}/>
</Tab.Navigator>
</NavigationContainer>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: Colors.darkBackgroundColor,
}
});
Run Code Online (Sandbox Code Playgroud)
付款视图
export default class PaymentScreen extends Component{
render() {
return (
<View style={styles.container}>
<Text style={styles.text}>Payments!</Text>
</View>
)
}
}
const styles = StyleSheet.create({
container:{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: Colors.backgroundColor,
},
text:{
color: Colors.textColor
}
});
Run Code Online (Sandbox Code Playgroud)
pgr*_*931 12
经过一些试验和错误,我自己弄清楚了。的 Tab.Navigator类NavigationContainer有一个名为的道具tabBarOptions,它以样式表作为其style选项。当然,组件的边框也可以在这里更改。
不过这里有一个问题:设置borderWidth为 0 不会隐藏导航上方的白色边框。只有设置borderTopWidth为 0才能达到预期的效果。
所以完整的解决方案如下所示:
<NavigationContainer>
<Tab.Navigator
tabBarOptions={{
activeTintColor: Colors.tabIconSelected,
inactiveTintColor: Colors.tabIconDefault,
style: styles.container
}}/>
</NavigationContainer>
const styles = StyleSheet.create({
container: {
backgroundColor: Colors.darkBackgroundColor,
borderTopWidth: 0
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2463 次 |
| 最近记录: |