我正在尝试创建一个简单的应用程序,其中包含一个原生的反应按钮,但到目前为止,每次我运行我的代码时,它都会给我一个错误,说“"无法找到变量:按钮"”。我想在顶部(已经完成)和屏幕中央的一个按钮结束我的标题,触摸时会发出警报。
我已经完成了几个在线教程,无法找到解决方案。
这是我的代码:
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
class Project extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.Title}>
Lucas's App
</Text>
<View style={styles.buttonContainer}>
<Button
onPress={() => { Alert.alert('You tapped the button!')}}
title="Press Me"
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
Title: {
color: '#000000',
marginTop: 13,
paddingLeft:100,
paddingRight:100,
fontFamily: 'Avenir',
fontSize: 30,
},
buttonContainer: {
margin: 20
},
});
AppRegistry.registerComponent('Project', () => Project);
提前致谢。
答案 0 :(得分:11)
您需要确保导入按钮。 您可以在代码之前添加:
int64_t
[或只是将按钮添加到导入列表]