In my app I'm creating a tab using TabViewAnimated. I need those each tab to have different colors. I tried that in many ways but didn't work. This is the output I got till now.
What I want is given below.
This is my code.
import React, { PureComponent } from 'react';
import { View, StyleSheet, Dimensions } from 'react-native';
import { TabViewAnimated, TabBar, SceneMap } from 'react-native-tab-view';
const initialLayout = {
height: 0,
width: Dimensions.get('window').width,
};
const FirstRoute = () => {
return (
<View style={[styles.container, styles.FirstRouteStyle]} />
);
};
const SecondRoute = () => {
return (
<View style={[styles.container, styles.SecondRouteStyle]} />
);
};
const ThirdRoute = () => {
return (
<View style={[styles.container, styles.ThirdRouteStyle]} />
);
};
export default class TabView extends PureComponent {
state = {
index: 0,
routes: [
{ key: 'first', title: 'First', tabStyle: { backgroundColor: 'red' } },
{ key: 'second', title: 'Second', tabStyle: { backgroundColor: 'green' } },
{ key: 'third', title: 'Third', tabStyle: { backgroundColor: 'blue' } },
],
};
_handleIndexChange = index => this.setState({ index });
_renderScene = SceneMap({
first: FirstRoute,
second: SecondRoute,
third: ThirdRoute,
});
_renderHeader(props) {
return (
<TabBar
{...props}
style={styles.tabbar}
tabStyle={styles.tabStyle}
labelStyle={styles.labelStyle}
/>
)
}
render() {
return (
<TabViewAnimated
style={styles.container}
navigationState={this.state}
renderScene={this._renderScene}
renderHeader={this._renderHeader}
onIndexChange={this._handleIndexChange}
initialLayout={initialLayout}
/>
);
}
}
const styles = {
container: {
flex: 1,
},
FirstRouteStyle: {
backgroundColor: '#ff4081'
},
SecondRouteStyle: {
backgroundColor: '#673ab7'
},
ThirdRouteStyle: {
backgroundColor: 'yellow'
},
tabbar: {
//backgroundColor: 'green',
height: 100,
justifyContent: 'center'
},
tabStyle: {
},
labelStyle: {
},
tablabel: {
backgroundColor: 'transparent',
color: 'black',
fontSize: 12,
margin: 4,
}
};
As I have studied tabStyle can be used to style individual tabs. I used that but it didn't work. Please help me to add different colors as I mentioned above.

