You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除@react-navigation/material-bottom-tabs中激活按钮的背景色

移除@react-navigation/material-bottom-tabs激活按钮背景色的方法

你可以通过配置导航器的screenOptions属性直接解决这个问题,具体有两种常用方式:

  • 直接设置激活标签的背景为透明:
    在创建Tab导航器时,给screenOptions添加tabBarActiveBackgroundColor: 'transparent',这会直接覆盖激活状态下的按钮背景色。

  • 如果上述方法未生效,可配置指示器样式:
    针对底部标签的激活指示器,设置activeIndicatorStyle将其背景设为透明,彻底移除默认的高亮背景。

完整代码示例:

import { createMaterialBottomTabNavigator } from '@react-navigation/material-bottom-tabs';

const Tab = createMaterialBottomTabNavigator();

function MyTabs() {
  return (
    <Tab.Navigator
      screenOptions={{
        tabBarActiveBackgroundColor: 'transparent',
        activeIndicatorStyle: {
          backgroundColor: 'transparent',
        },
      }}
    >
      {/* 这里添加你的页面路由配置 */}
    </Tab.Navigator>
  );
}

如果依然存在样式冲突,你可以自定义tabBarButton组件,完全控制按钮的激活状态样式:

import { TouchableOpacity } from 'react-native';

// 在Tab.Navigator的screenOptions中添加
screenOptions={{
  tabBarButton: (props) => (
    <TouchableOpacity
      {...props}
      style={{
        ...props.style,
        backgroundColor: props.accessibilityState.selected ? 'transparent' : 'transparent',
      }}
    >
      {props.children}
    </TouchableOpacity>
  ),
}}

内容的提问来源于stack exchange,提问作者teteyi3241

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 14:05:19