【发布时间】:2019-08-26 10:23:56
【问题描述】:
我正在用 React Native 编写导航栏。可以将其视为双层——上层是汉堡菜单、标题和搜索图标,第二层由三个可触摸的标题组成,用于导航到相关屏幕。
a mock-up of the navbar I'm trying to create
当我应用内联样式时,它们会起作用。当我在那里执行 Stylesheet.create 并应用样式时,它们不会。我是编程新手,很困惑。
我的计划是编写一个单独的导航栏,该导航栏分为两行(视图):navbarTop 和 navbarBottom。我非常感谢您了解这样做是否有意义,以及如何解决我的样式问题。非常感谢大家!
import React, { Component } from 'react';
import { View, Text, StyleSheet, Image, TouchableHighlight } from 'react-native';
import { withNavigation } from 'react-navigation';
class Navbar extends Component {
render() {
return (
<View style={styles.navbarTop}>
<View>
<TouchableHighlight
onPress={() => {
this.props.navigation.openDrawer();
}}
>
<Image
style={{marginBottom: 5}}
source={require('./../../../android/app/src/main/res/drawable/menu.png')}
/>
</TouchableHighlight>
</View>
<View>
<Text
style={{
fontWeight: 'bold',
color: 'white',
fontSize: 20,
marginRight: 70
}}
>
Dashboard
</Text>
</View>
<View>
<Image
style={{marginBottom: 5}}
source={require('./../../../android/app/src/main/res/drawable/search.png')}
/>
</View>
<View style={styles.navbarBottom}>
<View>
<Text
style={{
color: 'white',
fontSize: 15,
marginRight: 70
}}
> RECORDINGS </Text>
</View>
<View>
<Text
style={{
color: 'white',
fontSize: 15,
marginRight: 70
}}
> PATIENTS </Text>
</View>
<View>
<Text
style={{
color: 'white',
fontSize: 15,
marginRight: 70
}}
> DEVICES </Text>
</View>
</View>
</View>
);
}
}
export default withNavigation(Navbar);
const styles = StyleSheet.create({
navbarTop: {
backgroundColor: '#14172B',
padding: 10,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'flex-end',
},
// navbarBottom: {
// }
});
【问题讨论】:
-
嗨@dereknahman,在 CSS 中,内联样式比内部和外部 CSS 具有更高的优先级。这就是为什么你的内联 CSS 只在这里工作。尝试检查其他 CSS 是否对您的 CSS 产生影响。
标签: css react-native react-native-android