Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set backgroundColor and Badge for Tabnavigator in React-Navigation

In React-Native with React-Navigation I have a Tabnavigator like so:

const testScreenNavigator = TabNavigator({
    Tab1: { screen: Tab1Screen },
    Tab2: { screen: Tab2Screen },
    Tab3: { screen: Tab3Screen },
});
testScreenNavigator.navigationOptions = {
    title: 'MY TITLE',
    header: {
        titleStyle:{
        },
        style:{
// how to set the options?
        },
    }  
}

Now I want to do 2 things:

  1. Set the backgroundColor: 'red' of the Tabs in Android (not iOS bottom tabs)
  2. Have a badge next to Tab1: e.g.

Tab1 (2) | Tab2 | Tab3

Regards

like image 704
user3819370 Avatar asked Mar 01 '17 21:03

user3819370


1 Answers

  • Set the backgroundColor for Header and Tab

To set background color for Header use navigationOptions and to set background color for Tab use tabBarOptions. See below code

const testScreenNavigator = TabNavigator ({
  Tab1: { screen: RecentChatsScreen },
  Tab2: { screen: AllContactsScreen },
  Tab3: { screen: AllContactsScreen}
}, {
  tabBarOptions : {
    style: {
      backgroundColor: '#42a5f5',
    }
  }
});

testScreenNavigator.navigationOptions = {
  title: 'MY TITLE',
  header: {
    style: {
      backgroundColor: '#42a5f5',
    }
  },
};

below is output

enter image description here

like image 198
Kishan Vaghela Avatar answered Sep 23 '22 02:09

Kishan Vaghela