如何在 TextInput 中添加前缀 - React Native

Aki*_*nda 0 textinput react-native react-native-ios

我想在我的文本输入中添加前缀,我想知道如何做到这一点。

文本输入代码

        <TextInput
          style={styles.inputs}
          placeholder="Mobile Number"
          keyboardType="number-pad"
          underlineColorAndroid="transparent"
          onChangeText={mobile_number => this.setState({mobile_number})}
        />
Run Code Online (Sandbox Code Playgroud)

我想要的最终输出

维

tin*_*tos 6

你可以这样做:

  render() {
    return (
      <View style={styles.inputContainer}>
        <Text style={styles.prefix}>+94</Text>
        <TextInput
          placeholder="Mobile Number"
          keyboardType="number-pad"
          underlineColorAndroid="transparent"
          onChangeText={mobile_number => this.setState({ mobile_number })}
        />
      </View>
    )
  }
Run Code Online (Sandbox Code Playgroud)
const styles = StyleSheet.create({
  inputContainer: {
    borderWidth: 1,
    flexDirection: 'row',
    alignItems: 'center',
    backgroundColor: 'white',
    marginHorizontal: 10,
    borderRadius: 10
  },
  prefix: {
    paddingHorizontal: 10,
    fontWeight: 'bold',
    color: 'black'
  }
})
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述