gpt4 book ai didi

react-native - 如何在react-native-tab-view中更改所选选项卡的背景颜色

转载 作者:行者123 更新时间:2023-12-03 14:43:52 29 4
gpt4 key购买 nike

我使用 react-native-tab-view。那么如何仅将背景颜色设置为选定的选项卡?
这就是我所拥有的...

<TabView
navigationState={this.state}
renderScene={SceneMap({
first: FirstRoute,
second: SecondRoute,
third: ThirdRoute,
fourth: FourthRoute,
})}
onIndexChange={index => this.setState({ index })}
initialLayout={{ width: Dimensions.get('window').width, height: Dimensions.get('window').height }}
useNativeDriver = {true}
renderTabBar={(props) =>
<TabBar
{...props}
indicatorStyle={{ backgroundColor: 'white' }}
style={{backgroundColor: "black", height: 40}}
renderIcon={this.renderIcon}
indicatorStyle={{backgroundColor: "#555555"}}
/>
}
/>


谢谢!

最佳答案

这适用于文本样式更改。您的情况唯一的区别是,而不是更改 renderlabel 内的“文本”标签上的样式您必须更改“查看”标签的样式。

renderLabel={({ route }) => {
return (
<View> //THIS IS WHERE YOU PUT THE CONDITIONAL STYLING
<Text
style={
route.key === props.navigationState.routes[this.state.index].key
? styles.selectedTabTextStyle
: styles.label
}
>
{route.title}
</Text>
</View>
);
}}

关于react-native - 如何在react-native-tab-view中更改所选选项卡的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51266810/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com