Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

backgroundColor not working on View

Tags:

react-native

I'm trying to set a background color of a view. I set everything in here:

  import React, { Component } from 'react';
  import { View, StyleSheet, Text } from 'react-native';
  export default class Login extends Component{
    render(){
      return(
         <View style={styles.container}>
          <Text>
            Hello.
          </Text>
         </View>
      );
    }
  }

 const styles = StyleSheet.create({
   container:{
       flex: 1,
       flexDirection: 'column',
       alignItems: 'center',
       justifyContent: 'center',
       backgroundColor: 'rgba(79, 81, 140, 1.0)',
     }
 });

The problem is that the view is staying with white color. I tried to add text to the view to see if it's background color is changing and it does. How can I set the background color of the view to be a color I choose? I searched the net but couldn't find anything..

like image 480
John Doah Avatar asked Apr 18 '17 16:04

John Doah


1 Answers

Remove flex:1 from the container style, it will work.

like image 141
Shweta Avatar answered Nov 12 '22 13:11

Shweta