react-native - 如何在 React-Native (Expo) 中调整图标的大小?
问题描述
我想从中删除像“Home”和“Explore”这样的文本:
StatusBar.setBarStyle('dark-content');
if (Platform.OS === 'android') StatusBar.setBackgroundColor('#fff');
if (home) {
StatusBar.setHidden(true);
if (Platform.OS === 'android') {
StatusBar.setBackgroundColor('#fff');
StatusBar.setBarStyle('light-content');
}
} else {
StatusBar.setHidden(false);
}
return (
<Tab.Navigator
labeled={false}
shifting={false}
barStyle={{
backgroundColor: home ? '#000' : '#fff',
}}
initialRouteName="Home"
activeColor={home ? '#fff' : '#000'}
>
<Tab.Screen
name="Home"
component={Home}
listeners={{
focus: () => setHome(true),
blur: () => setHome(false),
}}
options={{
tabBarLabel: 'Home',
tabBarIcon: ({ color }) => (
<FontAwesome name="home" size={32} color={color} />
),
}}
/>
<Tab.Screen
name="Discover"
component={Discover}
options={{
tabBarLabel: 'Explore',
tabBarIcon: ({ color }) => (
<AntDesign name="search1" size={30} color={color} />
),
}}
/>
我改变了size
fromfontawesome
和antdesign
to 32
/ 30
。现在我的图标更大了,但图标不完整。图标被切成两半。我想我需要使用padding
,但我没有这个样式。有什么帮助吗?谢谢!
解决方案
那是因为您将它们放置在 TabNavigator 中,要让它们进入,您必须使 TabNavigator 更大,如下所示:
tabBarOptions={{
style:{height:300}
}}
所以你的代码:
StatusBar.setBarStyle('dark-content');
if (Platform.OS === 'android') StatusBar.setBackgroundColor('#fff');
if (home) {
StatusBar.setHidden(true);
if (Platform.OS === 'android') {
StatusBar.setBackgroundColor('#fff');
StatusBar.setBarStyle('light-content');
}
} else {
StatusBar.setHidden(false);
}
return (
<Tab.Navigator
labeled={false}
shifting={false}
barStyle={{
backgroundColor: home ? '#000' : '#fff',
}}
initialRouteName="Home"
activeColor={home ? '#fff' : '#000'}
tabBarOptions={{
style:{height:300}
}}
>
<Tab.Screen
name="Home"
component={Home}
listeners={{
focus: () => setHome(true),
blur: () => setHome(false),
}}
options={{
tabBarLabel: 'Home',
tabBarIcon: ({ color }) => (
<FontAwesome name="home" size={100} color={color} />
),
}}
/>
<Tab.Screen
name="Discover"
component={Discover}
options={{
tabBarLabel: 'Explore',
tabBarIcon: ({ color }) => (
<AntDesign name="search1" size={50} color={color} />
),
}}
/>
推荐阅读
- azure-active-directory - B2C ID 令牌中缺少电话号码声明
- performance - 相同的 Hasura 查询以截然不同的执行时间执行
- r - R中多个固定参数的应用函数
- list - 如何将项目添加到具有多个对象的列表中?
- javascript - 在 JS 中调整元素的高度
- paytm - Paytm 交易响应返回 null Bundle (android)
- llvm - 如何仅使用一个 arg 调用 LLVM IR arg?
- regex - 正则表达式负前瞻忽略代码部分
- java - 如何通过 Redisson 客户端通过 RMap 检查该值是否已存在于 Redis 中?
- javascript - 多分页?