简体   繁体   English

在 Android 上更改高度时,react-native TextInput 显示错误

[英]react-native TextInput displays wrong when changing height on Android

I have a TextInput with the following style:我有一个具有以下样式的 TextInput:

amountInput: {
  flex: 1,
  backgroundColor: 'rgba(255, 255, 255, 0.1)',
  color: 'rgba(255, 255, 255, 0.9)',
},

On iOS it correctly looks like it doesn't have enough padding:在 iOS 上,它看起来好像没有足够的填充:

在此处输入图片说明

On Android is has enormous padding by default:在 Android 上,默认情况下有巨大的填充:

在此处输入图片说明

Not a problem - I'll set a right and left padding, and a height:没问题 - 我将设置左右填充和高度:

amountInput: {
  flex: 1,
  backgroundColor: 'rgba(255, 255, 255, 0.1)',
  height: 30,
  paddingRight: 5,
  paddingLeft: 5,
  color: 'rgba(255, 255, 255, 0.9)',
}

Looks good on iOS:在 iOS 上看起来不错:

在此处输入图片说明

But Android messes up:但是 Android 搞砸了:

在此处输入图片说明

How can I make an Android input box like the penultimate iOS screenshot?如何制作像倒数第二个 iOS 屏幕截图一样的 Android 输入框? Thanks.谢谢。

Android 在顶部和底部添加了一些默认填充,您可以通过将paddingVertical: 0添加到元素的样式来重置它们。

For me it was text alignment issue in Android.对我来说,这是 Android 中的文本对齐问题。 Adding textAlignVertical: 'top' to the style fixed it for me.textAlignVertical: 'top'添加到样式中为我修复了它。

To make the text input look the same on both iOS and Android.使文本输入在 iOS 和 Android 上看起来相同。 Give it a specific height, this will override the default height in android.给它一个特定的高度,这将覆盖 android 中的默认高度。

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

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