android - react native 按钮不可见

标签 android button react-native

我正在尝试制作一个简单的登录屏幕,其中我有 2 个 TextInputs 和一个 View 内的按钮。

TextInputs 是可见的,但是当我把它放在 View 中时按钮是不可见的

下面是登录界面的代码

import React, { Component } from 'react';

import {
  StyleSheet,
  Text,
  View,
  Image,
  TextInput,
  Alert,
  Button
} from 'react-native';


export default class Login extends Component {

    constructor(props) {
         super(props);
        this.state = {};
    }

    onButtonPress= () => {
        Alert.alert('Button has been pressed!');
        };

    render() {
    return (
        <View style={{flexDirection: 'column', padding: 20}}>

            <View style={{justifyContent: 'center',alignItems: 'center',height:250}}>
                <Image style={{height:100}} source={require('../img/jpeg.jpg')} />
            </View>

            <View style={{flex:1}}>
                <TextInput
                    style={{height: 40, borderColor: 'gray', borderWidth: 1,marginBottom:10}}
                    onChangeText={(text) => this.setState({text})}          
                    value={this.state.text}
                    placeholder="Username"
                 />
                 <TextInput
                    style={{height: 40, borderColor: 'gray', borderWidth: 1}}
                    onChangeText={(password) => this.setState({password})}          
                    value={this.state.password}
                    placeholder="Password"
                    password={true} 
                 />
                  <Button 
                    onPress={()=> {this.onButtonPress()}}
                    title='Add ToDo'
                    style={{height:40,backgroundColor:'#1e90ff'}}/>         


            </View >   

      </View>
    );
  }

}

添加高度也不起作用。 如果我删除按钮并将其添加到 View 之外,那么我将变得可见

截图 button not visible

这是一件简单的事情,但行不通。

最佳答案

你忘了在你的 Root View 中添加 flex:1

<View style={{flex:1,flexDirection: 'column', padding: 20}}>

关于android - react native 按钮不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44063588/

相关文章:

android - Google Tag Manager Android - 不支持 JSONArrays

javascript - 我找不到函数名

jquery效果-向下/向上滑动隐藏div,隐藏当前显示的隐藏div

javascript - react native : How to create text with fixed character widths

reactjs - 动态加载组件以从外部 url react native 应用程序

android - Popup 出现在 DialogFragment 后面

android - Unity 2019 - 无法启用 MultiDex 支持

react-native - 以正确的格式获取当前时间 - React-Native

Android:从 sdk 管理器更新我的 android sdk 后

html - 固定按钮上的小可点击区域