react-native - React-Native View 中的 TextInput 边框和宽度

标签 react-native

我有一个包含以下内容的 react native View :

<View style={styles.section}>
          <Text style={styles.h2}>
            NAME
          </Text>
          <TextInput style={styles.input} placeholder="Name" />
          <Text style={styles.h2}>
            EMAIL
          </Text>
          <TextInput style={styles.input} placeholder="Password" />
        </View>  

input: {
    height: 30,
    flex: 0.7,
    fontSize: 13,
    padding: 4,
    borderBottomColor: '#fff',
    borderRightColor: 'transparent',
    borderLeftColor: 'transparent',
    borderTopColor: 'transparent',
    borderTopWidth: 0,
    borderBottomWidth: 0.5,
  },

不幸的是,这没有显示边框(而不是所需的下划线边框),并且两个输入框都占据了全屏(而不是我想要的 0.7 flex)。我该如何解决?

最佳答案

除非启用多行,否则您无法直接在 TextInput 上声明特定边框,您可以查看此 link .

我将 TextInput 包装在 View 中,然后向 View 添加边框,如果您不希望文本输入为全宽,我只需在左侧和右侧添加边距。

将 TextInput 包装在 View 内:

<View style={styles.section}>
           <Text style={styles.h2}>
             NAME
           </Text>
           <View style={styles.inputView}>
            <TextInput style={styles.input} placeholder="Name" />
           </View>
           <Text style={styles.h2}>
             EMAIL
           </Text>
           <View style={styles.inputView}>
              <TextInput style={styles.input} placeholder="Password" />
           </View>
</View>

这些 View 的样式:

input: {
  height: 40,
  fontSize: 13,
  padding: 4,
},
section:{
  marginLeft:10,
  marginRight:10,
},
inputView:{
  borderBottomColor: '#fff',
  borderBottomWidth: 0.5,
}

关于react-native - React-Native View 中的 TextInput 边框和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39970955/

相关文章:

javascript - 如何将 HoC 与 React Native 结合使用

android - 将 React 或 React Native 嵌入到现有的移动应用程序中

android - react native Android : Generating Signed APK through Android Studio doesn't include JS Bundle

css - react native : is it possible to achieve align-Item:flex-start style in React native?

react-native - 与流服务器的连接已关闭。查看输出以获取更多信息

ios - 使用 React Native 构建 IOS : ld: framework not found FIRAnalyticsConnector

react-native - 带钩子(Hook)的 apploading splashscreen

android - 应用程序 :installDebug Task while attempting to run react-native app on MI MAX 2 android device 期间的 SecurityException

node.js - 尝试使用 React Native 创建项目时出错

当 Prop 更改时,React-native FlatList 不会重新渲染行