React Native 当选项卡处于活动状态时,如何删除背景色?

ffdz8vbo  于 2023-02-09  发布在  React
关注(0)|答案(1)|浏览(129)

有人知道如何抛出这个恼人的背景色时,标签是活跃的?我尝试了很多解决方案,但我仍然有问题

function TabsAndroid() {
  return (
    <TabAndroid.Navigator
      sceneAnimationEnabled={true}
      barStyle={{ backgroundColor: colors.primary }}
      screenOptions={({ route }) => ({
        tabBarIcon: ({ color, focused }) => {
          let iconStr: string = "";
          if (route.name === "Tab1")
            return (
              <Image
                source={{
                  uri: "https://imgs.search.brave.com/70390jQSfVsjPzoOaHb96nE2lssrdYkr0HOVLKagutE/rs:fit:1024:1024:1/g:ce/aHR0cDovL2ljb25z/Lmljb25hcmNoaXZl/LmNvbS9pY29ucy9w/YW9tZWRpYS9zbWFs/bC1uLWZsYXQvMTAy/NC9zb2NpYWwtZmFj/ZWJvb2staWNvbi5w/bmc",
                }}
                style={{ width: 10, height: 20 }}
              />
            );
          if (route.name === "Tab2") iconStr = "T2";
          if (route.name === "StackNavigator") iconStr = "Stack";
          return <Text style={{ color }}>{iconStr}</Text>;
        },
      })}
      activeColor="#fff"
      inactiveColor="#ccc"
    >
      <TabAndroid.Screen
        name="Tab1"
        options={{ tabBarColor: "red" }}
        component={Tab1}
      />
      <TabAndroid.Screen name="Tab2" component={Tab2} />
      <TabAndroid.Screen name="StackNavigator" component={MyStack} />
    </TabAndroid.Navigator>
  );
}

我尝试了最老的解决方案,我只得到改变文本颜色时,用户点击标签,但没有为图标

41zrol4v

41zrol4v1#

您需要在screenOptions中更改背景颜色。
https://reactnavigation.org/docs/bottom-tab-navigator/#screenoptions 这个:

<Tab.Navigator screenOptions={{
            tabBarActiveTintColor: "red",
            tabBarInactiveTintColor: "blue",
            tabBarStyle: {
                 height: 55,
            },
            tabBarOptions: {
           style: {
                    backgroundColor: 'transparent',
                },
            },
        }}>

相关问题