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/

    相关文章:

    javascript - 组合堆栈、抽屉和选项卡导航器

    javascript - 如何在 render() 中没有 Spinner 组件的情况下显示 React Spinner

    react-native - 尝试为我的导航标题添加垂直边距但不起作用以及如何为导航标题添加底线

    reactjs - 通过在内部调用 navigation.navigate() 来制作共享组件 - React Native

    javascript - React Native 通过 `props` 构建的导航容器传递 `createStackNavigator`

    javascript - 当用户从列表中选择时如何显示内容详细信息?

    Android 应用程序在 OneSignal 推送通知上崩溃

    javascript - 如何仅针对导航器屏幕之一禁用抽屉导航滑动?

    javascript - 如何使用react-native处理android媒体(播放、暂停、停止)

    react-native - react native - 改变导航方向(即从右到左)