react-native - 设置 React Navigation 的 Material Top Tab Navigator 的高度样式属性

标签 react-native react-navigation

我正在使用 MaterialTopTabNavigator 制作顶部选项卡。但有一个风格问题。

我可以使用多种样式设置MaterialTopTabNavigator的样式。当我设置 tab 的高度时,容器的高度发生了变化,而不是我认为的 tab 。下面的图片是一个示例。

  1. 应用高度之前的样式对象
labelStyle: {
    color: '#7d3aff',
    fontSize: 12,
    lineHeight: 12,
    backgroundColor: '#a0f312',
  },
  tabStyle: {
    borderWidth: 1,
    borderColor: '#7d3aff',
    borderRadius: 10,
    backgroundColor: '#f012',
  },
  style: {
    backgroundColor: '#fff',
  },
  indicatorStyle: {
    height: 0,
  },

和选项卡图像。

enter image description here

  • 应用高度后的样式对象
  • labelStyle: {
        color: '#7d3aff',
        fontSize: 12,
        lineHeight: 12,
        backgroundColor: '#a0f312',
      },
      tabStyle: {
        height: 30, // the only change is here
        borderWidth: 1,
        borderColor: '#7d3aff',
        borderRadius: 10,
        backgroundColor: '#f012',
      },
      style: {
        // height: 30, // there is no difference do it or apply height in tabStyle
        backgroundColor: '#fff',
      },
      indicatorStyle: {
        height: 0,
      },
    

    和选项卡图像

    enter image description here

    如您所见,高度应用于标签栏容器,而不是标签标签栏>,即选项卡的高度没有变化。

    如何将高度应用于每个选项卡?

    最佳答案

    原因是minHeightmaxHeighttabStyle 对象默认具有 minHeight。因此,如果您设置了 minHeightmaxHeight,那么您可以将 height 应用于它。

    tabStyle: {
        borderWidth: 1,
        borderColor: colors.primary,
        borderRadius: 10,
        backgroundColor: '#f012',
        minHeight: 10,
        maxHeight: 30,
      },
    

    enter image description here

    关于react-native - 设置 React Navigation 的 Material Top Tab Navigator 的高度样式属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58009906/

    相关文章:

    react-native - 如何在 React Native 中备份/恢复 SQLite 数据库

    javascript - 与 React Native 中的容器相比,Lottie 动画非常小

    react-native - React Navigation - goBack() 会自动调用堆栈导航器屏幕

    javascript - 在组件中设置viewpager的页面

    android - 除了 Android 上的 React Native,iOS 上是否有类似 RCTBridge React Native 的东西?

    javascript - Firebase:如何在 React Native 中异步更新记录的值?

    reactjs - 如何解决 'this navigator has both navigation and container props'错误

    android - 没有导航 Prop 的 React Navigation 在 Release模式下不起作用(Android 签名的应用程序)

    reactjs - React Navigation "focus"事件监听器不使用更新值

    react-native - 在 react 导航中动态更改 DrawerNavigator 的 drawerPosition 配置