[英]TextInput Not Showing In React Native
I'm fairly new to react native and am trying to create an app that gives you a current stock price.我对原生反应还很陌生,我正在尝试创建一个应用程序,为您提供当前的股票价格。 I'm creating the design for the app to show to the people helping me.
我正在创建应用程序的设计,以向帮助我的人展示。 I have some code looking like this
我有一些看起来像这样的代码
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View, TextInput, SafeAreaView} from 'react-native';
export default function App() {
return (
<View style={styles.container}>
<TextInput style={styles.inp} />
<View style={styles.container}>
<Text style={styles.titleText}>$150.32</Text>
<Text>±$2.10</Text>
</View>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
titleText: {
fontFamily: "AppleSDGothicNeo-Light",
fontSize:75
},
basicText: {
fontFamily: "AppleSDGothicNeo-Light",
fontSize:2
},
container2: {
flexDirection:'row',
justifyContent:'flex-end',
alignItems:'flex-start'
},
inp: {
height:40
}
});
The thing is the TextInput is not showing.问题是 TextInput 没有显示。 I've followed some other questions and added a height but it still doesn't show.
我已经关注了其他一些问题并添加了一个高度,但它仍然没有显示。 How do I fix this?
我该如何解决?
Try to add this for input style :尝试为输入样式添加此内容:
inp: {
height: 40,
margin: 12,
borderWidth: 1,
padding: 10,
}
It is working to me.它对我有用。
You can se in image: React native text input你可以在图片中看到: React native text input
You have to first create state for textinput value like so您必须首先像这样为 textinput 值创建状态
const [text, setText] = useState("");
Also apply value and onChangeText props to the textinput something like below还将 value 和 onChangeText 道具应用于 textinput,如下所示
<TextInput
style={styles.inp}
onChangeText={setText}
value={text}
/>
where setText will update the text value that is entered into the textinput.其中 setText 将更新输入到文本输入中的文本值。
You can refer to this as well https://reactnative.dev/docs/textinput你也可以参考这个https://reactnative.dev/docs/textinput
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.