2016-11-12 344 views
3

我在React Native中使用TextInput,如果我尝试向组件添加边框,那么在我的彩色边框上总是有一个正方形的黑色边框。React Native TextInput总是有黑色边框

enter image description here

当我删除我的彩色边框组件看起来是这样的:

enter image description here

这里是我的代码:

<TextInput 
     returnKeyType="search" 
     style={searchStyle.searchInput} 
     onChangeText={(text) => this.setState({text})} 
     placeholder={this.state.searchText} 
     onSubmitEditing={(event) => this.searchLocationSubmit(event)} 
/> 

const searchStyle = StyleSheet.create({ 
    searchInput : { 
    height: 35, 
    color: '#64AFCB', 
    borderColor: '#64AFCB', 
    borderWidth: 1, 
    borderStyle: 'solid', 
    borderRadius: 15, 
    width: 200, 
    marginLeft: 10, 
    marginTop: 10, 
    backgroundColor: 'white', 
    position: 'absolute', 
    zIndex: 2 
    } 
}) 

回答

1

尝试删除borderStyle: 'solid'

0

尽量的

borderWidth: 1, 
1

接受的答案

borderWidth: 0, 

istead并没有真正回答你的问题。

如果要设置TextInput的边框颜色,似乎在React Native中会有一个错误,它会覆盖TextInput上的borderColor样式并将其设置为黑色。

为了解决这个问题,我把我的TextInput标签包装在View中。我将TextInput的borderWidth设置为0,然后将包装视图设置为使我想要在输入上看到的边框样式。

<View style={{borderStyle: 'solid', borderWidth: 1, borderColor: '#64AFCB'}}> 
    <TextInput 
     placeholder="MyInput" 
     style={{borderWidth: 0}} 
     value={this.state.myInputValue} 
     /> 
</View>