如何更改TextInput
元素内的文本输入颜色,以响应本机元素,我尝试将color="red"
传递给组件,但由于某种原因,它无法工作。
下面是我使用的代码:
import React, { useState } from "react";
import { StyleSheet, View } from "react-native";
import { Text, Button, Input } from "react-native-elements";
import Icon from "react-native-vector-icons/MaterialIcons";
import colors from "../config/colors";
function LoginScreen() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
return (
<View style={styles.Input}>
<Input
style={styles.TextInput}
placeholder="Your email"
value={email}
onChangeText={setEmail}
autoCapitalize="none"
autoCorrect={false}
leftIcon={<Icon name="email" size={20} color="#B3C1B3" />}
/>
<Input
secureTextEntry
placeholder="Your password"
value={password}
onChangeText={setPassword}
autoCapitalize="none"
autoCorrect={false}
leftIcon={<Icon name="lock" size={20} color="#B3C1B3" />}
/>
</View>
);
}
const styles = StyleSheet.create({
Input: {
top: "2%",
width: "70%",
left: "15%",
justifyContent: "center",
alignItems: "center",
},
});
export default LoginScreen;
发布于 2020-05-20 08:41:33
您需要添加inputStyle
来更改输入的样式。
<Input
style={styles.TextInput}
inputStyle={{color: 'red'}} // Add this to your code
placeholder="Your email"
value={email}
onChangeText={setEmail}
autoCapitalize="none"
autoCorrect={false}
leftIcon={<Icon name="email" size={20} color="#B3C1B3" />}
/>
发布于 2020-05-20 08:38:47
这个表达式不会工作,因为它不是实际的css。
const styles = StyleSheet.create({
Input: {
top: "2%",
width: "70%",
left: "15%",
justifyContent: "center",
alignItems: "center",
},});
根据本机元素文档的反应,您必须传递包含自定义css的样式对象,properties.You可以这样实现。
function LoginScreen() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const styles={ color:'red' };
return (
<View style={styles.Input}>
<Input
placeholder="Comment"
leftIcon={{ type: 'font-awesome', name: 'comment' }}
style={styles}
onChangeText={value => this.setState({ comment: value })}
/>
</View>
);
}
https://stackoverflow.com/questions/61918125
复制相似问题