如何为密码输入设置 TextInput 的本机应答样式

我有一个文本输入。当用户输入文本时,我希望它显示密码点/星号(****) ,而不是显示实际输入的文本。我怎么能这么做?

<TextInput
style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
onChangeText={(text) => this.setState({input: text})}
/>
250716 次浏览

当这个问题是没有办法做到这一点,本地,但是这将被添加到下一个同步根据 这个拉请求。 下面是对拉请求的最后一条评论——“内部着陆,将在下一次同步中出来”

当它被添加时,你将能够做这样的事情

<TextInput secureTextEntry={true} style={styles.default} value="abc" />

参考文献

您可以在官方网站上获得示例和示例代码,如下所示:

<TextInput password={true} style={styles.default} value="abc" />

参考资料: http://facebook.github.io/react-native/docs/textinput.html

本地版本 < strong > 0.55.2

这种方法很有效:

secureTextEntry={true}

这种方法不再有效:

password={true}

我必须补充一句:

secureTextEntry={true}

还有

password={true}

从0.55开始

secureTextEntry={true}

或者只是

secureTextEntry

属性。

工作范例:

<TextInput style={styles.input}
placeholder="Password"
placeholderTextColor="#9a73ef"
returnKeyType='go'
secureTextEntry
autoCorrect={false}
/>

TextInput 必须包含 secureTextEntry = { true } ,请注意 React 的文档状态是不能同时使用 multiline = { true } ,因为不支持这种组合。

您还可以设置 textContentType = {‘ password’} ,以允许字段从存储在手机上的密钥链中检索凭据,如果您在手机上获得了生物识别输入,那么这是一种输入凭据的替代方法,可以快速插入凭据。比如 iPhone X 上的 FaceId 或者其他 iPhone 机型和 Android 上的指纹触摸输入。

 <TextInput value={this.state.password} textContentType={'password'} multiline={false} secureTextEntry={true} onChangeText={(text) => { this._savePassword(text); this.setState({ password: text }); }} style={styles.input} placeholder='Github password' />

再加一点:

version = RN 0.57.7


secureTextEntry={true}

keyboardType"phone-pad""email-address"时不工作

只需将下面的行添加到 <TextInput>

secureTextEntry={true}

如果你增加了 secureTextEntry={true},但没有工作,然后检查 multiline={true}支柱,因为如果它是真的,secureTextEntry不工作。

<TextInput
secureTextEntry
placeholder="password" placeholderTextColor="#297542"
autoCorrect={false} style={mystyles.inputStylee}
/>

您可以简单地将 secureTextEntry支持添加到 TextInput 并忽略它的值。默认情况下,它被设置为 true。使它成为假的做这个 secureTextEntry={false}

<TextInput
placeholderTextColor={colors.Greydark}
placeholder={'Enter Password'}
secureTextEntry={true} />

 <TextInput
placeholder="Password"
secureTextEntry={true}
style={styles.input}
onChangeText={setPassword}
value={password}
/>

您需要将 secureTextEntry道具设置为 true

<TextInput
placeholder="Re-enter password"
style={styles.input}
secureTextEntry={true}
value={confirmPsw}
onChangeText={setconfirmPsw}
/>