简体   繁体   English

React Native Android App中TextInput下的意外行

[英]Unexpected Lines under TextInput in React Native Android App

I am building an app using React Native and I get a weird unexpected line below every TextInput on my physical android device as shown below in the picture. 我正在使用React Native构建一个应用程序,我在物理android设备上的每个TextInput下面得到一个奇怪的意外行,如下图所示。 Also, the lines don't show up in the iOS simulator. 此外,这些行不会显示在iOS模拟器中。

在此输入图像描述

My code for the Input Component: 输入组件的代码:

import React from 'react';
import { TextInput, View, Text } from 'react-native';

const Input = ({ value,  onChangeText, placeholder, secureTextEntry }) => {
  const { inputStyle, labelStyle, containerStyle } = styles;

  return (
    <View style={containerStyle}>
      <TextInput
        secureTextEntry={secureTextEntry}
        placeholder={placeholder}
        autoCorrect={false}
        style={inputStyle}
        value={value}
        onChangeText={onChangeText}
      />
    </View>
  );
};

const styles = {
  inputStyle: {
    color: '#000',
    paddingRight: 5,
    paddingLeft: 5,
    fontSize: 14,
    lineHeight: 23,
    flex: 2,
  },
  containerStyle: {
    height: 40,
    flex: 1,
    flexDirection: 'row',
    alignItems: 'center',
    borderBottomWidth: 1,
    borderColor: '#ddd'
  }
};

export { Input };

According to React docs to remove the border: 根据React docs删除边框:

<TextInput underlineColorAndroid='transparent' />

TextInput has by default a border at the bottom of its view. TextInput默认情况下在其视图底部有一个边框。 This border has its padding set by the background image provided by the system, and it cannot be changed. 此边框的填充由系统提供的背景图像设置,无法更改。 Solutions to avoid this is to either not set height explicitly, case in which the system will take care of displaying the border in the correct position, or to not display the border by setting underlineColorAndroid to transparent. 避免这种情况的解决方案是要么不明确地设置高度,系统将负责在正确的位置显示边框,或者通过将underlineColorAndroid设置为透明来不显示边框。

Also you can try to disable autoCorrect tag. 您也可以尝试禁用autoCorrect标记。 It might help too: 它也可能有所帮助:

<TextInput autoCorrect={false} />

Credits: 积分:

  1. underlineColorAndroid underlineColorAndroid
  2. autoCorrect 自动更正

输入底部的边框是Android的自然行为,对于iOS没有边框底部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM