javascript - 如何在 react native 的页面上将 TextInput 居中?

标签 javascript reactjs react-native

当 TextInput 获得焦点并打开 android 键盘时,需要将 TextInput 在键盘上方的屏幕上居中。何去何从?

最佳答案

出于某种原因,justifyContent 不适用于 TextInput,因此只需使用边距即可。这是示例:

var styles = StyleSheet.create({
  textInput: {
    marginLeft: 50,
    marginRight: 50
  }
});

只需确保将样式设置为 TextInput:

<TextInput style={styles.textInput} />

差点忘了 - 不要设置宽度,使用边距来定义大小,否则将不起作用。

关于javascript - 如何在 react native 的页面上将 TextInput 居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35463119/

相关文章:

android - 如何在 React Native Android 中添加自定义字体

javascript - 无法使用 webpack 将 Base64 图像导入到 React 组件中

javascript - 如何在 React JS 中获取动态生成的输入字段的值?

reactjs - eslint `forbid-prop-types` 规则导致 Firefox 控制台窗口出现警告

javascript - React.js : How to run window. open() 连续多次?

javascript - 未处理的 promise 拒绝: TypeError: undefined is not a function evaluating 'departureloc.map' occurs when mapping for setState in react native

javascript - 将外部变量传递给 promise .then 而不调用它

javascript - jquery 中是否有 linkedin 配置文件 url 的内置验证?

javascript - Css 颜色 Jquery UI

javascript - 如何使任何子组件在 React Native 中变得模糊?