Dil*_*ain 11 react-native react-native-tab-view
我是 React-Native 的新手,正在学习它。在学习react-native-tab-view时,我尝试改变它的颜色,但经过几次尝试后我无法做到这一点。如果有人指导我如何更改默认为蓝色的选项卡栏的颜色,我将非常感激。这是 npm react-native-tab-view 的链接,这是一段代码。任何帮助将不胜感激。
import * as React from 'react';
import { View, StyleSheet, Dimensions } from 'react-native';
import { TabView, SceneMap } from 'react-native-tab-view';
const FirstRoute = () => (
<View style={[styles.scene, { backgroundColor: '#ff4081' }]} />
);
const SecondRoute = () => (
<View style={[styles.scene, { backgroundColor: '#673ab7' }]} />
);
const initialLayout = { width: Dimensions.get('window').width };
export default function TabViewExample() {
const [index, setIndex] = React.useState(0);
const [routes] = React.useState([
{ key: 'first', title: 'First' },
{ key: 'second', title: 'Second' },
]);
const renderScene = SceneMap({
first: FirstRoute,
second: SecondRoute,
});
return (
<TabView
navigationState={{ index, routes }}
renderScene={renderScene}
onIndexChange={setIndex}
initialLayout={initialLayout}
/>
);
}
const styles = StyleSheet.create({
scene: {
flex: 1,
},
});
Run Code Online (Sandbox Code Playgroud)
ken*_*try 19
更改标签栏的背景颜色
如果您参考本节,则在使用该属性声明自定义 React 组件后,必须传递选项卡栏的样式属性renderTabBar。
<TabView
navigationState={{ index, routes }}
renderScene={renderScene}
onIndexChange={setIndex}
initialLayout={initialLayout}
renderTabBar={props => <TabBar {...props} style={{backgroundColor: 'black'}}/>} // <-- add this line
/>
Run Code Online (Sandbox Code Playgroud)
更改标签栏的文本颜色
如果你参考这个,
<TabBar
renderLabel={({route, color}) => (
<Text style={{ color: 'black', margin: 8 }}>
{route.title}
</Text>
)}
style={{backgroundColor: 'white'}}
...
/>
Run Code Online (Sandbox Code Playgroud)
请随意使用示例零食进行进一步实验。:)
| 归档时间: |
|
| 查看次数: |
13405 次 |
| 最近记录: |