React-native 占位符在 Android 上仅部分可见
React-native placeholder only partially visible on Android
我在将 TextInput
居中并同时保持占位符可见时遇到问题。我希望文本从占位符开始的地方开始(居中)。
在 IOS 上可以使用,但在 android 上只能看到一部分。
IOS 的结果:
IOS placeholder
android 的结果:
Android placeholder
这是我的代码:
render() {
return (
<View style={styles.containerStyle}>
<TextInput
underlineColorAndroid='transparent'
placeholder={"Placeholder "}
placeholderTextColor={"grey"}
maxLength={6}
style={{ fontSize: 30, color: "black",
justifyContent: "center", }}
onChangeText={this.props.onChangeText}
value={this.props.value.toUpperCase()}
/>
</View>
);
}
}
const styles = {
containerStyle: {
flexDirection: 'row',
backgroundColor: "#fff",
borderRadius: 5,
borderWidth: 1,
shadowColor: "#000",
elevation: 2,
marginLeft: 5,
marginRight: 5,
alignItems: 'center',
justifyContent: "center"
}
};
在您的 TextInput
风格中使用 flex:1
<View style={styles.containerStyle}>
<TextInput
underlineColorAndroid='transparent'
placeholder={"Placeholder "}
placeholderTextColor={"grey"}
maxLength={6}
style={{ flex:1, fontSize: 30, color: "black",
justifyContent: "center", }}
onChangeText={this.props.onChangeText}
value={this.props.value.toUpperCase()}
/>
</View>
我在将 TextInput
居中并同时保持占位符可见时遇到问题。我希望文本从占位符开始的地方开始(居中)。
在 IOS 上可以使用,但在 android 上只能看到一部分。
IOS 的结果: IOS placeholder
android 的结果: Android placeholder
这是我的代码:
render() {
return (
<View style={styles.containerStyle}>
<TextInput
underlineColorAndroid='transparent'
placeholder={"Placeholder "}
placeholderTextColor={"grey"}
maxLength={6}
style={{ fontSize: 30, color: "black",
justifyContent: "center", }}
onChangeText={this.props.onChangeText}
value={this.props.value.toUpperCase()}
/>
</View>
);
}
}
const styles = {
containerStyle: {
flexDirection: 'row',
backgroundColor: "#fff",
borderRadius: 5,
borderWidth: 1,
shadowColor: "#000",
elevation: 2,
marginLeft: 5,
marginRight: 5,
alignItems: 'center',
justifyContent: "center"
}
};
在您的 TextInput
风格中使用 flex:1
<View style={styles.containerStyle}>
<TextInput
underlineColorAndroid='transparent'
placeholder={"Placeholder "}
placeholderTextColor={"grey"}
maxLength={6}
style={{ flex:1, fontSize: 30, color: "black",
justifyContent: "center", }}
onChangeText={this.props.onChangeText}
value={this.props.value.toUpperCase()}
/>
</View>