我是React本机开发的新手。在我的应用程序中,我有登录页面,在此登录页面中有两个textinput。在此文本输入中没有下划线。我已经尝试了许多方法,但并没有强调。在这里,我的要求是在inputtext下划线。那么如何获得下划线呢?
这是我的登录表单代码。
import React, {Component} from 'react';
import {StyleSheet, Text, View,TextInput,TouchableOpacity} from 'react-native';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>SEDC</Text>
<TextInput placeholder="Acct No/User Id" style={styles.textInput} multiline={true}></TextInput>
<TextInput placeholder="Password" style={styles.textInput}></TextInput>
<TouchableOpacity style={styles.btn} onPress={this.login}><Text>Log In</Text></TouchableOpacity>
</View>
);
}
login=()=>{
alert("testing......");
// this.props.navigation.navigate('Second');
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
textInput: {
alignSelf: 'stretch',
padding: 10,
marginLeft: 50,
borderBottomColor:'#000',
margin:5,
marginRight:50,
// backgroundColor: '#000',
},
btn:{
alignSelf: 'stretch',
backgroundColor: '#01c853',
padding: 10,
margin:10,
marginLeft: 100,
marginRight:100,
alignItems: 'center',
}
});
这是我的代码的输出。
我尝试使用borderBottomColor:'#000',但无法正常工作。所以请指导我如何做
预先感谢...
答案 0 :(得分:2)
除了设置底部边框的颜色外,还需要设置底部边框的“宽度”。
borderBottomWidth
属性定义了沿textInput组件底部边缘的边框粗细(以像素为单位)。因此,例如,您可以通过对样式进行以下调整,在textInput
底部的黑色边框上添加2像素的粗细:
textInput: {
alignSelf: 'stretch',
padding: 10,
marginLeft: 50,
borderBottomColor:'#000',
margin:5,
marginRight:50,
borderBottomColor: '#000', // Add this to specify bottom border color
borderBottomWidth: 2 // Add this to specify bottom border thickness
}
答案 1 :(得分:1)
刚刚设置
underlineColorAndroid={'black'}
答案 2 :(得分:1)
非常简单:我们需要在 TextInput 布局中传递我们的自定义样式,并完成显示下线的工作 通过这种自定义样式,我们可以执行 2 个操作 a.我们可以放置下划线 b.我们还可以为文本输入字段使用框
bottomBorder: {
marginLeft: 20,
marginRight: 20,
borderBottomColor: 'skyblue',//if we want only bottom line
borderBottomWidth: 2, // Add this to specify bottom border thickness &
//textDecorationLine: 'underline',
//borderColor:"skyblue",//if we want to show our TextInput field inside the box
//borderWidth:2 //use this to show width of border boxes
}
现在是时候将此自定义样式放入我们的 TextInput 布局中
<TextInput placeholder="Enter your Name "
style={ styles.bottomBorder}
onChangeText={(text) => {
console.warn(text)
}}
/>