Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change color of StatusBar #323

Closed
Deepankar01 opened this issue Nov 26, 2016 · 24 comments
Closed

Change color of StatusBar #323

Deepankar01 opened this issue Nov 26, 2016 · 24 comments

Comments

@Deepankar01
Copy link

Deepankar01 commented Nov 26, 2016

Is there any way i can change the color of StatusBar in NativeBase

i wrote this and nothing changed

<Header style={styles.header}>
                    <Container style={{flexDirection: 'row',}}>
                        <StatusBar
                            backgroundColor="blue"
                            barStyle="light-content"
                        />
                        <Navigator
                            initialRoute={{statusBarHidden: false}}
                            renderScene={(route, navigator) =>
                                <Container>
                                    <StatusBar hidden={route.statusBarHidden}/>
                                </Container>
                            }
                        />
                        <Image style={styles.headerIcon} source={images.Logo}>
                        </Image>

                    </Container>
                </Header>
@sankhadeeproy007
Copy link
Contributor

'StatusBar' should ideally wrap the component in the topmost level.

@mmmoli
Copy link

mmmoli commented Jan 28, 2017

Is there an example of this somewhere? Want to see some code.

@yossijacob
Copy link

Agree, not sure where am i supposed to put the StatusBar. if i put inside of content it works but only until the app returning from background. an example will be much appreciated.
In the react native docs they put it alongside the navigator but this does not work with native base.

from the react native docs

<View>
   <StatusBar
     backgroundColor="blue"
     barStyle="light-content"
   />
   <Navigator
     initialRoute={{statusBarHidden: true}}
     renderScene={(route, navigator) =>
       <View>
         <StatusBar hidden={route.statusBarHidden} />
         ...
       </View>
     }
   />
 </View>

@HyperSimon
Copy link

Is this problem solved? Is there any example? Why is this issue closed?

@PhiSpindler
Copy link

PhiSpindler commented Apr 7, 2017

You could use the StatusBarManager as work-around.

import {NativeModules, processColor } from 'react-native';
const { StatusBarManager } = NativeModules;

export default class DiscoverScreen extends Component {
  componentDidMount() {
    StatusBarManager.setColor(processColor('#ff0000'), false); 👈
  }
  render() {
    return ( ... );
  }
}

@jasonnathan
Copy link

@PhiSpindler setColor is not a function

@PhiSpindler
Copy link

oh ok, my bad - I only tested it on android, there it worked

@nacmonad
Copy link

nacmonad commented May 11, 2017

Hey! found a neat workaround/hack that you can implement inside any native-base <Container> component. the statusbar is a prop of the Header component, but when you want to change statusbar and not show the header, simply :
<Header androidStatusBarColor="#2c3e50" style={{display:'none'}}/>

@jacobokoenig
Copy link

Finally @nacmonad!!! Thanks!!

@prayash
Copy link

prayash commented Jul 12, 2017

Checking out the Header component source it looks like it takes a iosBarStyle prop for iOS and androidStatusBarColor for Android.

This works for me in iOS:

<Header iosBarStyle="light-content"> </Header>

Hope that helps!

@Amin52J
Copy link

Amin52J commented Jul 15, 2017

You can also simply import StatusBar from "react-native" module and put it inside the NativeBase Header component:

import {StatusBar} from 'react-native';
import {Container, Content, Header, Body, Title} from 'native-base';
.
.
.
export default class App extends React.Component {
  render() {
    return (
      <Container>
        <Header style={{backgroundColor:'#000'}}>
          <StatusBar barStyle="light-content"/>
          <Body>
            <Title style={{color:'#FFF'}}>My App</Title>
          </Body>
        </Header>
        <Content>
          //content of your app goes here
        </Content>
      </Container>
    );
  }
}

@Minaghorbaani
Copy link

hi , how can i make my statusbar background gradient ?

@abhishekgargx
Copy link

abhishekgargx commented Sep 5, 2018

Just put it as top element in Content, and make sure to import {StatusBar} from 'react-native'

render() {
       return (
           <Container>
               <Content >
                       <StatusBar
                              backgroundColor="#ff1c1c"
                              barStyle="light-content" />
                    //rest of your content
               </Content>
         </Container>
       );
    }
          

if you are using Header of Native base . then put it inside as top element like below

 render() {
        return (
            <Container >
                <Header>
                        <StatusBar
                            backgroundColor="#ff1c1c"
                            barStyle="light-content" />
                    // other header elements 
                </Header>
               <Content> 
                   // you content
              </Content>
          </Container>
        );
     }
          

@msmahesh91
Copy link

thank you so much @nacmonad

@shimatai
Copy link

@PhiSpindler setColor is not a function

It works only in Android.

@harikrishna1213
Copy link

Hey! found a neat workaround/hack that you can implement inside any native-base <Container> component. the statusbar is a prop of the Header component, but when you want to change statusbar and not show the header, simply :
<Header androidStatusBarColor="#2c3e50" style={{display:'none'}}/>
it's working....!!! great !!!!

@ashwithags
Copy link

ashwithags commented Mar 6, 2019

<Header iosBarStyle="light-content"> </Header>

this changed the text color to white. but the background color remain unchanged

@kajeevan025
Copy link

kajeevan025 commented Apr 24, 2019

<Header
        iosBarStyle="light-content"
        androidStatusBarColor="#2c3e50"
        style={{ backgroundColor: "#212B36" }}
      >
</Header>

This can be helpfull

@thanhluantl2304
Copy link

You can also simply import StatusBar from "react-native" module and put it inside the NativeBase Header component:

import {StatusBar} from 'react-native';
import {Container, Content, Header, Body, Title} from 'native-base';
.
.
.
export default class App extends React.Component {
  render() {
    return (
      <Container>
        <Header style={{backgroundColor:'#000'}}>
          <StatusBar barStyle="light-content"/>
          <Body>
            <Title style={{color:'#FFF'}}>My App</Title>
          </Body>
        </Header>
        <Content>
          //content of your app goes here
        </Content>
      </Container>
    );
  }
}

Perfect! I tested and run successfully! :D

@brownieboy
Copy link

brownieboy commented Sep 27, 2019

I must have tried the solutions on every one of these comments, but none of them worked for me. All I'm trying to do is get light coloured text for the status bar on iOS. (I already get light text by default on Android).

Is it tied to some particular version of NativeBase or React Native? I'm on React Native 0.59.1 and NativeBase 2.12.1. I'm not using Expo.

Update
It's working for me now.

I upgraded to RN 0.61 and putting <StatusBar barStyle="light-content"/> inside the <Header> component did the trick.

@truongthanh1303
Copy link

I must have tried the solutions on every one of these comments, but none of them worked for me. All I'm trying to do is get light coloured text for the status bar on iOS. (I already get light text by default on Android).

Is it tied to some particular version of NativeBase or React Native? I'm on React Native 0.59.1 and NativeBase 2.12.1. I'm not using Expo.

Update
It's working for me now.

I upgraded to RN 0.61 and putting <StatusBar barStyle="light-content"/> inside the <Header> component did the trick.

Hi @brownieboy , I got the same issue with React Native 0.59.9, native-base 2.13.8. Do you have any ideas without upgrade the RN version?
Thanks,

@brownieboy
Copy link

brownieboy commented Dec 17, 2019

@truongthanh1303,

Hi @brownieboy , I got the same issue with React Native 0.59.9, native-base 2.13.8. Do you have any ideas without upgrade the RN version?

Sorry, no.

The RN 0.61 upgrade also fixed a lot of other problems that I was having, so it was well worth the effort.

@rajan-keypress
Copy link

import {StatusBar} from 'react-native';
import {Container, Content, Header, Body, Title} from 'native-base';
.
.
.
export default class App extends React.Component {
render() {
return (

<Header style={{backgroundColor:'#000'}}>


<Title style={{color:'#FFF'}}>My App</Title>



//content of your app goes here


);
}
}

this is work for me

@zoobibackups
Copy link

Hey! found a neat workaround/hack that you can implement inside any native-base <Container> component. the statusbar is a prop of the Header component, but when you want to change statusbar and not show the header, simply :
<Header androidStatusBarColor="#2c3e50" style={{display:'none'}}/>

thank. it worked for me. I was searching for the solution in react native for the last 2 weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests