首页 > 解决方案 > 如何使 react-native-tab-view 的 TabBar 变小?

问题描述

我正在使用react-native-tab-view,但 TabBar 很大,我想让它变小。如何定制它?应用边距/填充 0 不起作用。应用小高度有效,但文本丢失。如何使它更小或更可定制?

<TabView
 ...
                renderTabBar={props =>
                    <TabBar
                        {...props}
                        indicatorStyle={{ backgroundColor: 'white' }}
                        style={{ backgroundColor: 'pink' }}
                        tabStyle={{ backgroundColor: 'teal' }}
                        renderLabel={({ route, focused, color }) => (
                            <Text style={{ color, margin: 8 }}>
                                {route.title}
                            </Text>
                        )}

                }

标签: reactjsreact-nativereact-native-tab-view

解决方案


尝试使用tabStyle道具TabBar。默认情况下,它一个样式:

minHeight: 48,

所以在你的情况下:

<TabView
 ...
  renderTabBar={props =>
      <TabBar
          {...props}
          indicatorStyle={{ backgroundColor: 'white' }}
          style={{ backgroundColor: 'pink' }}
          tabStyle={{ backgroundColor: 'teal', minHeight: 30 }} // here
          renderLabel={({ route, focused, color }) => (
              <Text style={{ color, margin: 8 }}>
                  {route.title}
              </Text>
          )}
    }

推荐阅读