我如何使TextInput显示输入文本的开头,而不是在Android中显示结尾?

问题描述 投票:13回答:3

我的本机应用程序中有一个TextInput。当我设置值prop且该值比TextInput的长度长时,它将显示从头开始而不是从头开始的文本。在iOS中可以正常使用,这似乎是Android问题。有没有一种方法可以对齐文本,使其从TextInput的开头显示,还是首选?

这是我看到的:

enter image description here

这就是我想要的:

enter image description here

这是我的代码

<TextInput
defaultValue={address}
ref="searchInput"
autoCorrect={false}
style={searchStyles.searchInputField}
placeholderTextColor={'#ddd'}
placeholder="Location"
onChangeText={query => this.search(query)}
/>
android react-native textinput
3个回答
4
投票
<TextInput value={address} autoFocus={true} selection={{start:0, end:0}} />

也许有更好的方法可以做到这一点,但这是我想出的希望对其他人有所帮助的方法。


0
投票

0
投票
将代码放在onEndEditing中以及您想在其中更新文本的任何位置。
或同时更新文本和选择:

this.inputRef && this.inputRef.setNativeProps({ text: value, selection: { start: 0, end: 0 } })

© www.soinside.com 2019 - 2024. All rights reserved.