我在react native中有以下代码

import React, {Component} from 'react';
import {TabNavigator} from 'react-navigation';
import {View} from 'react-native';

class Home extends Component {

  static navigationOptions = {
        title:'Home',
        tabBarLabel:'First'
  };

  render() {
    return <View></View>;
  }

}

const tabOptions = {

    tabBarOptions: {
        activeTintColor:'white',
        inactiveTintColor:'#D3D3D3',
        style:{
            backgroundColor:'green',
            borderTopWidth:1,
            borderTopColor:'#D3D3D3'
        },
        tabBarSelectedItemStyle: {
            borderBottomWidth: 2,
            borderBottomColor: 'red',
        },
    },
}

const ProductNavigator = TabNavigator({
  First: {screen: Home},
  Second:{screen: Home}
},
tabOptions
);
export default ProductNavigator;

这就是它在Android emulator中呈现时的样子

enter image description here

I want the yellow underline to be RED underline instead. But my rules for 100 that declare a red underline are not being acknowledged. How do I make the underline of selected tab bar items to be red?

推荐答案

要设置TabNavigator所选项目指示器的样式,可以使用indicatorStyle.

indicatorStyle-选项卡指示器的样式对象(选项卡底部的线).

Example

const tabOptions = {    
    tabBarOptions: {
        activeTintColor:'white',
        inactiveTintColor:'#D3D3D3',
        style:{
            backgroundColor:'green',
            borderTopWidth:1,
            borderTopColor:'#D3D3D3'
        },
        indicatorStyle: {
            backgroundColor: 'red',
        },
    },
}

const ProductNavigator = TabNavigator({
  First: {screen: Home},
  Second:{screen: Home}
}, tabOptions);

React-native相关问答推荐

我们如何才能将我们自己的应用程序(IOS)排除在共享表中?

为什么当键盘出现在react native 时我的按钮会上升?按钮视图位置是绝对的?

react-native 自定义视图,原生 prop 没有 propType

如何在 React Native 中正确地将组件导入到我的导航器中?

在 TouchableOpacity 上创建 Raised凸起或Shadow阴影效果

最近 react-native 版本中的Unable to resolve moduledebuggerWorker 错误

iPhone 6s plus 上的字体大小

迷失在 Ionic、Cordova 等混合应用程序框架中

React-Native + crypto:如何在 React-Native 中生成 HMAC?

你能在 Ubuntu 上构建 React Native 应用程序(Android 应用程序)吗?

@react-navigation/stack 与 @react-navigation/native-stack 有什么区别?

试图注册两个同名的视图 RNGestureHandlerButton

React-Native 应用程序中来自 Babel 的未知选项错误

如何在react native中过滤对象数组?

React Native:无法点击调试菜单

使用来自另一个页面的 fetch 调用函数返回结果值

ExpoKit 和 React Native 元素的区别

react-native图像预取

在 react-native 中使用捏拉zoom 的可滚动图像

/bin/sh: adb: 找不到命令