DrawerNavigator:更改文本颜色
IT技术
reactjs
react-native
react-navigation
2021-04-26 15:55:42
4个回答
谷歌搜索将我带到这里,但答案无法解决我的问题:我想更改文本颜色,但根据活动和或非活动状态在不同颜色之间切换。更改标签样式的颜色有效地确保标签无论状态如何都是相同的颜色。所以我在抽屉的内容选项中使用了色调颜色。
export const DrawerStack = DrawerNavigator(
{... /drawer items}
,
{
contentOptions: {
activeTintColor: colors.primary,
activeBackgroundColor: 'transparent',
inactiveTintColor: 'black',
inactiveBackgroundColor: 'transparent',
labelStyle: {
fontSize: 15,
marginLeft: 10,
},
},
drawerWidth: SCREEN_WIDTH * 0.7,
drawerOpenRoute: 'DrawerOpen',
drawerCloseRoute: 'DrawerClose',
drawerToggleRoute: 'DrawerToggle',
}
);
通过这种方式,我可以使用选项根据抽屉项目是否处于活动状态来改变颜色activeTintColor and inactiveTintColor
。
而不是style
您需要使用labelStyle
内部 contentOptions。像这样:
contentOptions: {
labelStyle: {
fontFamily: 'SomeFont',
color: 'white',
},
}
对于使用 Navigation V5 的任何人,您都必须遵循以下方法并在初始化抽屉导航器时执行此操作
<Drawer.Navigator
drawerContentOptions={{
activeTintColor: 'red',
activeBackgroundColor: 'grey',
inactiveTintColor: 'blue',
inactiveBackgroundColor: 'white',
labelStyle:{
marginLeft:5
}
}}>
</Drawer.Navigator>
您可以参考文档以获取更多props https://reactnavigation.org/docs/drawer-navigator/#drawercontentoptions
您可以呈现您的自定义label
:
import { DrawerItem } from '@react-navigation/drawer';
// ...
<DrawerItem label={() => <Text style={{ color: '#fff' }}>White text</Text>} />;
https://reactnavigation.org/docs/drawer-navigator/#providing-a-custom-drawercontent
其它你可能感兴趣的问题