为什么我的占位符不会出现在 TextInput 中

Why won't my placeholder show up in TextInput

我不明白为什么占位符不会出现在两个 <TextInput> 上。此外,当用户键入内容时,<TextInput> 框中不会显示任何内容。我想知道为什么会这样。

这里是App.js:

import React, {Component} from 'react';
import {View, StyleSheet} from 'react-native';
import BackGround from './components/BackGround';

export default class App extends Component {
    render() {
        return(
            <View style={styles.back}>
                <BackGround/>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    back: {
        flex: 1
    }
});

这里是Login.js:

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

class Login extends Component {
    render() {
        return(
            <View>
                <TextInput
                    placeholder={"Email"}
                    placeholderTextColor={"#E365F4"}
                    style={styles.input}
                />

                <TextInput
                    placeholder={"Password"}
                    placeholderTextColor={"#f44242"}
                    style={styles.input}
                />

                <TouchableOpacity>
                    <Text style={styles.loginAndCA}>Login</Text>
                </TouchableOpacity>

                <TouchableOpacity>
                    <Text style={styles.loginAndCA}>Create Account</Text>
                </TouchableOpacity>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    input: {
        backgroundColor: 'green',
        paddingBottom: 20,
        padding: 20,
        paddingHorizontal: 150,
        marginBottom: 10
    },

    loginAndCA: {
        fontSize: 40,
        textAlign: 'center',
        color: 'white',
        fontFamily: 'Bodoni 72 Smallcaps'
    }
});

export default Login;

这里是BackGround.js:

import React, {Component} from 'react';
import {StyleSheet, Image, View} from 'react-native';
import Login from './Login';

export default class BackGround extends Component {
    render() {
        return(
            <View style={styles.first}>
                <Image style={styles.container} source={require('../pictures/smoke.jpg')}>
                    <View style={styles.second}>
                        <Login/>
                    </View>
                </Image>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        width: null,
        height: null,
        backgroundColor: 'rgba(0,0,0,0)',
        resizeMode: 'cover'
        // resizeMode: 'contain' // Shows image completely.
    },

    first: {
        flex: 1
    },

    second: {
       paddingTop: 290 // Moves both <TextInput> boxes down.
    }

});`

这里有三个问题,都是关于你的造型的。

  1. 通过使用 paddingBottom: 20padding: 20,您可以有效地将 TextInput 中可以显示的内容缩减为一小部分(如果是的话)。为了弥补这一点,您还需要调整 height
  2. 当你调整height时,你可能运行变成。我不知道此问题是否已得到修复,但如果您仍然遇到问题,请查看它。
  3. 最后,paddingHorizontal: 150 将它水平推得太远,什么也没有出现。将其减少到更小的值,例如 paddingHorizontal: 15.