react-native - 如何使drawerItem的activeTIntColor和activebackgroundColor在反应导航6中工作?
问题描述
我无法在 react-navigation 6 中更改 drawerItem 的 activeTintColor 和 activeBackgroundColor,即使我在抽屉项目上使用这些道具,我也看不到所选项目中 activeItem tintColor 变化的任何变化。下面是我的代码'正在使用我使用道具 activeTintColor 设置活动 DrawerItem 色调颜色的位置,但我没有看到颜色的任何变化,甚至我看不到我在哪个活动选项卡上,但导航工作正常。我能够导航到 DrawerItem 屏幕,只有它选择的活动项目似乎没有应用 activeTintColor 等
function DrawerNavigation() {
return (
<NavigationContainer>
<Drawer.Navigator
screenOptions={{
headerShown: false
}}
drawerContent={(nav) => {
const { navigation } = nav;
let state = navigation.getState();
return (
<View style={{ flex: 1 }}>
<View style={{ alignItems: "center" }}>
<View
style={{
height: 100,
width: 100,
borderColor: "black",
borderWidth: 1,
borderRadius: 50,
marginVertical: 10,
overflow: "hidden"
}}
>
<Image
source={{
uri: "https://m.cricbuzz.com/a/img/v1/192x192/i1/c170661/virat-kohli.jpg"
}}
resizeMode="cover"
style={{ width: "100%", height: "100%" }}
/>
</View>
</View>
<View style={{ flex: 1 }}>
<DrawerItem
label="Home"
pressColor="red"
icon={() => (
<Image
source={require("../assets/home.png")}
style={{ height: 25, width: 25 }}
/>
)}
onPress={() => navigation.navigate("Home")}
activeTintColor="red"
/>
<DrawerItem
label="Profile"
pressColor="red"
icon={() => (
<Image
source={require("../assets/profile.png")}
style={{ height: 25, width: 25 }}
/>
)}
onPress={() => navigation.navigate("Profile")}
activeTintColor="red"
/>
<DrawerItem
label="Cart"
pressColor="red"
icon={() => (
<Image
source={require("../assets/cart.png")}
style={{ height: 25, width: 25 }}
/>
)}
onPress={() => navigation.navigate("Cart")}
activeTintColor="red"
/>
</View>
</View>
);
}}
>
<Drawer.Screen name="HomeStack" component={StackNavigation} />
</Drawer.Navigator>
</NavigationContainer>
);
}
解决方案
in your <Drawer.Navigator/> There is a property named option which takes an
object and in that object you can find the drawerActiveTintColor Property. That
can be used to set the activeTintColor and it will change the background color
as well.
<NavigationContainer>
<Drawer.Navigator initialRouteName="Home">
<Drawer.Screen name="Home" component={HomeScreen}
options={{ drawerActiveTintColor: 'red' }}/>
<Drawer.Screen name="Notifications" component={NotificationsScreen} />
</Drawer.Navigator>
</NavigationContainer>
推荐阅读
- javascript - 带有子元素的水平 DIV,按 Id 滚动到
- .net-core - 使用 Apereo CAS 发布的 net core 加密 JWT 解码
- tableau-api - 获取表格中链接字段的完整日期范围
- java - 如何在redhat服务中运行一个由python包装的java程序
- javascript - 如何更新“componentDidUpdate”中的 React 元素?
- javascript - 如何分配数组中的所有对象?
- git - 尝试从 git 历史记录中删除大文件时,refs/heads/master 未更改
- compatibility - 如何在 avro 模式中向嵌套映射添加新类型时保持 FULL_TRANSITIVE 兼容性?
- bash - 创建函数来执行显示时间算术
- html - 限制引导页面的总宽度?