22

使用 React 本机 0.26,

我的组件是这样的

const Search = () => {
    return (
      <View style={styles.backgroundImage}>
        <TextInput style={styles.textInput} onChangeText={(text) => console.log(text)} placeholder={"Enter Search Term"}/>
      </View>
    )
}

我的风格:

const styles = StyleSheet.create({
  backgroundImage: {
    flex : 1,
    flexDirection: "column",
    justifyContent: 'center',
    alignItems: 'center'
  },
  textInput: {
    justifyContent: "center",
    alignItems: "stretch",
    borderRightWidth: 30,
    borderLeftWidth: 30,
    height: 50,
    borderColor: "#FFFFFF",
  }
})

我面临的问题是

  1. 边框右宽和左宽似乎没有任何效果,占位符文本只是从左边缘开始。
  2. TextInput 的背景为“灰色”,与视图的背景相同。我期待它默认为白色,(感觉透明)。
  3. 使用 iOS 模拟器如何调出键盘,我想设置returnKeyType并查看键盘的外观(并有一些代码onSubmitEditing和测试)。

截图如下: 截屏

4

3 回答 3

32

1 除非启用多行,否则您不能直接在 TextInput 上声明特定边框(例如borderLeftWidth,除非multiline={true}启用但borderWidth会起作用),但您可以将 TextInput 包装在 View 中并给它一个边框。

inputContainer: {
  borderLeftWidth: 4,
  borderRightWidth: 4,
  height: 70
},
input: {
  height: 70,
  backgroundColor: '#ffffff',
  paddingLeft: 15,
  paddingRight: 15
}

2 您需要backgroundColor为 TextInput 声明一个。

3 要显示本机键盘,您需要进入模拟器菜单并断开硬件。转到硬件-> 键盘-> 连接硬件键盘,将其关闭。

于 2016-05-25T04:21:42.123 回答
12

至于react-native: 0.61.5你可以直接borderBottomWidth在 TextInput 上设置。像下面的内联样式或者如果你想要单独的样式对象。

  style = {{borderBottomWidth : 1.0}}
于 2019-12-23T08:57:08.500 回答
1

默认情况下,boderWidth 将设置为 0。因此,使用borderWidth : 5(Top, Right, Bottom, Left) 的默认值。

如果您想单独分配宽度,您可以选择,

style = {{
borderStartWidth : 2
borderEndWidth : 3
borderTopWidth : 1
boderLeftWidth: 2
borderRightWidth: 3
borderBottomWidth : 4
}}
于 2020-01-21T11:19:56.553 回答