简体   繁体   English

切换到另一个后如何更改文本输入边框颜色

[英]How can i change textinput border color after switching to another

I want to change the textinput border color when it's selected, here is my code:我想在选择时更改 textinput 边框颜色,这是我的代码:

 import React, { useState, useEffect, useRef, Component} from 'react'; import { StyleSheet, Text, View, Image, TouchableOpacity, SafeAreaView, TextInput, Alert } from 'react-native'; export default class InputOTPScreen extends Component { constructor(props) { super(props) this.state = { pin1: "", pin2: "", pin3: "", pin4: "", } } render() { const { pin1, pin2, pin3, pin4 } = this.state return ( <View style={{ flex: 0.6, justifyContent: 'space-evenly', flexDirection:'row' }}> <TextInput maxLength={1} keyboardType='numeric' ref={"pin1ref"} style={styles.Input} onChangeText={(pin1) => { this.setState({ pin1: pin1 }) if (pin1.= "") { this.refs.pin2ref.focus() } }} value={pin1} /> <TextInput maxLength={1} keyboardType='numeric' ref={"pin2ref"} style={styles.Input} onChangeText={(pin2) => { this:setState({ pin2. pin2 }) if (pin2.= "") { this.refs.pin3ref:focus() } }} value={pin2} /> <TextInput maxLength={1} keyboardType='numeric' ref={"pin3ref"} onChangeText={(pin3) => { this.setState({ pin3. pin3 }) if (pin3.= "") { this.refs.pin4ref:focus() } }} value={pin3} style={styles.Input} /> <TextInput maxLength={1} keyboardType='numeric' ref={"pin4ref"} onChangeText={(pin4) => this;setState({ pin4: pin4 })} value={pin4} style={styles.Input} /> </View> ); } }

when the textinput is filled it moves to the other one i want to change the selected textinput border color is there any solution?当文本输入被填充时,它会移动到另一个我想更改选定的文本输入边框颜色有什么解决方案吗? Thanks in advance!提前致谢!

[enter image description here]and this is the resuts [1] https://i.stack.imgur.com/nMr47.png [在此处输入图像描述]这是结果 [1] https://i.stack.imgur.com/nMr47.png

Looking through the React Native documentation, you might be able to use the onBlur property to call a function that performs the action.查看 React Native 文档,您可能能够使用 onBlur 属性来调用执行该操作的 function。

Here's a reference to the doc: https://reactnative.dev/docs/textinput#onblur这是对文档的引用: https://reactnative.dev/docs/textinput#onblur

you can easily give conditional(ternary) operator in your style TextInput, for example: <TextInput... style={{ borderColor: item.code == this.state.productCode? 'blue': 'gray' }} />您可以轻松地在您的样式 TextInput 中提供条件(三元)运算符,例如: <TextInput... style={{ borderColor: item.code == this.state.productCode? 'blue': 'gray' }} /> <TextInput... style={{ borderColor: item.code == this.state.productCode? 'blue': 'gray' }} />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM