导入_this
import {AppRegistry, Text, View, Button, StyleSheet} from 'react-native';
这是我的 React Button 代码但样式不起作用 Hare …
<Button
onPress={this.onPress.bind(this)}
title={"Go Back"}
style={{color: 'red', marginTop: 10, padding: 10}}
/>
我也尝试过这段代码
<Button
containerStyle={{padding:10, height:45, overflow:'hidden',
borderRadius:4, backgroundColor: 'white'}}
style={{fontSize: 20, color: 'green'}}
onPress={this.onPress.bind(this)} title={"Go Back"}
> Press me!
</Button>
更新问题:
我也尝试过这种方式..
<Button
onPress={this.onPress.bind(this)}
title={"Go Back"}
style={styles.buttonStyle}
>ku ka</Button>
风格
const styles = StyleSheet.create({
buttonStyle: {
color: 'red',
marginTop: 20,
padding: 20,
backgroundColor: 'green'
}
});
原文由 MD Ashik 发布,翻译遵循 CC BY-SA 4.0 许可协议
React Native Button 的功能非常有限,请看; 按钮
它没有 style 道具,并且您没有像
<Button>txt</Button>
那样将文本设置为“网络方式”,而是通过标题属性<Button title="txt" />
如果您想更好地控制外观,您应该使用 TouchableXXXX 组件之一,例如 TouchableOpacity 它们真的很容易使用:-)