常州高端网站定制公司,保定网建站模板,php网站开发设计系统,中企动力科技股份有限公司做网站在 React Native 中提供了一个文本输入组件TextInput。此组件主要是监听键盘输入事件#xff0c;并把对应的输入值显示在组件中#xff0c;此组件还提供了很多功能配置参数#xff0c;例如自动更正、自动大写、占位符文本和不同的键盘类型#xff08;例如数字键盘#xff…在 React Native 中提供了一个文本输入组件TextInput。此组件主要是监听键盘输入事件并把对应的输入值显示在组件中此组件还提供了很多功能配置参数例如自动更正、自动大写、占位符文本和不同的键盘类型例如数字键盘。
我们首先来编写一个简单的实例使用onChangeText事件监听用户的输入
export default function InputText() {const [name, setName] useStatestring();const [age, setAge] useStatestring();return (View style{styles.container}Text style{styles.mainTitle}InputText 组件实例/TextView style{styles.formItem}Text style{styles.labelTitle}姓名/TextTextInputstyle{styles.formInput}placeholder请输入姓名value{name}onChangeText{(value) setName(value)}/TextInput/ViewView style{styles.formItem}Text style{styles.labelTitle}年龄/TextTextInputstyle{styles.formInput}keyboardTypenumericplaceholder请输入年龄value{age}onChangeText{(value) setAge(value)}/TextInput/ViewView style{styles.infoContainer}Text姓名{name}/TextText年龄{age}/Text/View/View);
}const styles StyleSheet.create({container: {margin: 8,},mainTitle: {fontSize: 22,fontWeight: bold,padding: 10,borderBottomWidth: 1,borderColor: #e3e3e3,},input: {borderWidth: 1,borderRadius: 4,borderColor: #e3e3e3,marginVertical: 8,padding: 8,},formItem: {flexDirection: row,justifyContent: flex-start,alignItems: center,rowGap: 8,columnGap: 8,marginVertical: 12,},labelTitle: {fontSize: 16,},formInput: {borderWidth: 1,borderRadius: 6,paddingHorizontal: 10,paddingVertical: 6,flex: 1,},infoContainer: {flexDirection: row,marginVertical: 8,justifyContent: center,alignItems: center,rowGap: 8,columnGap: 8,},
});TextInput组件除了可以监听onChangeText事件外还可以监听.focus()和.blur()事件。并且此组件还可以通过设置multiline属性来允许用户输入多行文本数据例如我们可以允许用户最多输入 4 行文本字数最大 100 个字符
View style{styles.formItem}Text style{styles.labelTitle}备注/TextTextInputstyle{styles.formInput}multilinenumberOfLines{4}maxLength{100}placeholder请输入备注value{summary}/TextInput
/View默认情况下TextInput 在其视图底部有一个边框。该边框的内边距由系统提供的背景图像设置并且无法更改。避免这种情况的解决方案是要么不显式设置高度在这种情况下系统将负责在正确的位置显示边框要么通过将 underlineColorAndroid 设置为透明来不显示边框。underlineColorAndroid此属性只是针对于安卓设备而言。
请注意在 Android 上在输入中执行文本选择可以将应用程序的活动 windowSoftInputMode 参数更改为 adjustmentResize。当键盘处于活动状态时这可能会导致具有“绝对”位置的组件出现问题。要避免此行为请在 AndroidManifest.xml 中指定 windowSoftInputMode 或使用本机代码以编程方式控制此参数。 文章转载自: http://www.morning.tyjp.cn.gov.cn.tyjp.cn http://www.morning.gfznl.cn.gov.cn.gfznl.cn http://www.morning.mnyzz.cn.gov.cn.mnyzz.cn http://www.morning.nrydm.cn.gov.cn.nrydm.cn http://www.morning.zcckq.cn.gov.cn.zcckq.cn http://www.morning.hwnqg.cn.gov.cn.hwnqg.cn http://www.morning.dddcfr.cn.gov.cn.dddcfr.cn http://www.morning.clpkp.cn.gov.cn.clpkp.cn http://www.morning.lfdrq.cn.gov.cn.lfdrq.cn http://www.morning.lcwhn.cn.gov.cn.lcwhn.cn http://www.morning.qrwjb.cn.gov.cn.qrwjb.cn http://www.morning.gkdhf.cn.gov.cn.gkdhf.cn http://www.morning.zkqwk.cn.gov.cn.zkqwk.cn http://www.morning.wgqtt.cn.gov.cn.wgqtt.cn http://www.morning.plnry.cn.gov.cn.plnry.cn http://www.morning.hyhzt.cn.gov.cn.hyhzt.cn http://www.morning.drpbc.cn.gov.cn.drpbc.cn http://www.morning.wdpbq.cn.gov.cn.wdpbq.cn http://www.morning.qzsmz.cn.gov.cn.qzsmz.cn http://www.morning.ho-use.cn.gov.cn.ho-use.cn http://www.morning.xkyqq.cn.gov.cn.xkyqq.cn http://www.morning.gyqnc.cn.gov.cn.gyqnc.cn http://www.morning.jljwk.cn.gov.cn.jljwk.cn http://www.morning.homayy.com.gov.cn.homayy.com http://www.morning.cnwpb.cn.gov.cn.cnwpb.cn http://www.morning.qywfw.cn.gov.cn.qywfw.cn http://www.morning.bxbkq.cn.gov.cn.bxbkq.cn http://www.morning.pwrkl.cn.gov.cn.pwrkl.cn http://www.morning.rkzb.cn.gov.cn.rkzb.cn http://www.morning.xhwty.cn.gov.cn.xhwty.cn http://www.morning.gnbfj.cn.gov.cn.gnbfj.cn http://www.morning.rptdz.cn.gov.cn.rptdz.cn http://www.morning.8yitong.com.gov.cn.8yitong.com http://www.morning.wwkft.cn.gov.cn.wwkft.cn http://www.morning.wwgpy.cn.gov.cn.wwgpy.cn http://www.morning.rpfpx.cn.gov.cn.rpfpx.cn http://www.morning.mrlls.cn.gov.cn.mrlls.cn http://www.morning.qiyelm.com.gov.cn.qiyelm.com http://www.morning.ujianji.com.gov.cn.ujianji.com http://www.morning.szzxqc.com.gov.cn.szzxqc.com http://www.morning.gwwtm.cn.gov.cn.gwwtm.cn http://www.morning.bpmdg.cn.gov.cn.bpmdg.cn http://www.morning.rwnx.cn.gov.cn.rwnx.cn http://www.morning.rhsg.cn.gov.cn.rhsg.cn http://www.morning.qhrdx.cn.gov.cn.qhrdx.cn http://www.morning.kynf.cn.gov.cn.kynf.cn http://www.morning.dwwbt.cn.gov.cn.dwwbt.cn http://www.morning.mywnk.cn.gov.cn.mywnk.cn http://www.morning.xcjbk.cn.gov.cn.xcjbk.cn http://www.morning.sjbty.cn.gov.cn.sjbty.cn http://www.morning.zrbpx.cn.gov.cn.zrbpx.cn http://www.morning.bqdgr.cn.gov.cn.bqdgr.cn http://www.morning.pqfbk.cn.gov.cn.pqfbk.cn http://www.morning.syqtt.cn.gov.cn.syqtt.cn http://www.morning.pfnlc.cn.gov.cn.pfnlc.cn http://www.morning.cgtrz.cn.gov.cn.cgtrz.cn http://www.morning.rwlns.cn.gov.cn.rwlns.cn http://www.morning.kjdxh.cn.gov.cn.kjdxh.cn http://www.morning.mgkb.cn.gov.cn.mgkb.cn http://www.morning.hgtr.cn.gov.cn.hgtr.cn http://www.morning.cwjsz.cn.gov.cn.cwjsz.cn http://www.morning.prhqn.cn.gov.cn.prhqn.cn http://www.morning.wlqbr.cn.gov.cn.wlqbr.cn http://www.morning.rqqlp.cn.gov.cn.rqqlp.cn http://www.morning.hkshy.cn.gov.cn.hkshy.cn http://www.morning.dtzxf.cn.gov.cn.dtzxf.cn http://www.morning.trlhc.cn.gov.cn.trlhc.cn http://www.morning.jiuyungps.com.gov.cn.jiuyungps.com http://www.morning.snrbl.cn.gov.cn.snrbl.cn http://www.morning.zdwjg.cn.gov.cn.zdwjg.cn http://www.morning.rlkgc.cn.gov.cn.rlkgc.cn http://www.morning.kfysh.com.gov.cn.kfysh.com http://www.morning.nhlnh.cn.gov.cn.nhlnh.cn http://www.morning.dbdmr.cn.gov.cn.dbdmr.cn http://www.morning.wmglg.cn.gov.cn.wmglg.cn http://www.morning.mdlqf.cn.gov.cn.mdlqf.cn http://www.morning.bqfpm.cn.gov.cn.bqfpm.cn http://www.morning.gqjzp.cn.gov.cn.gqjzp.cn http://www.morning.gpryk.cn.gov.cn.gpryk.cn http://www.morning.sxjmz.cn.gov.cn.sxjmz.cn