更改反应本机tabBar的背景颜色

时间:2020-02-04 16:09:24

标签: javascript react-native react-navigation react-navigation-stack react-navigation-bottom-tab

因此,我真的很想与本地和移动开发人员互动, 我想更改底部标签栏导航的背景颜色,但是我似乎无法弄清楚该怎么做,因为我从一个带有导航功能的本机项目开始(在expo init阶段选择),因此如何编写内容与网上看到的内容不同,我知道我需要添加

      tabBarOptions: {
        style: { backgroundColor: 'orange'}
      }

但是老实说idk到底在哪里,如果有人可以帮助的话,将不胜感激! 这是我的代码:

import React from 'react';
import { Platform } from 'react-native';
import { createStackNavigator } from 'react-navigation-stack';
import { createBottomTabNavigator } from 'react-navigation-tabs';

import TabBarIcon from '../components/TabBarIcon';
import HomeScreen from '../screens/HomeScreen';
import LinksScreen from '../screens/LinksScreen';
import SettingsScreen from '../screens/SettingsScreen';


const config = Platform.select({
  web: { headerMode: 'screen' },
  default: {},
});

const HomeStack = createStackNavigator(
  {
    Home: HomeScreen,
  },{
    defaultNavigationOptions: {
      headerTintColor: '#444',
      headerStyle: {
        backgroundColor: 'pink'
      }
    }
  },
  config
);

HomeStack.navigationOptions = {
  tabBarLabel: 'Home',
  tabBarIcon: ({ focused, tintColor }) => (
    <TabBarIcon
      focused={focused}
      name={
        Platform.OS === 'ios'
          ? `ios-information-circle${focused ? '' : '-outline'}`
          : 'md-information-circle'
      }
      color= {"#cd077dr"}
    />
  ), style: {
    backgroundColor: 'pink'
  }
};

HomeStack.path = '';

const LinksStack = createStackNavigator(
  {
    Links: LinksScreen,
  },{
    defaultNavigationOptions: {
      headerTintColor: '#444',
      headerStyle: {
        backgroundColor: 'pink'
      }
    }
  },
  config
);

LinksStack.navigationOptions = {
  tabBarLabel: 'Links',
  tabBarIcon: ({ focused }) => (
    <TabBarIcon focused={focused} name={Platform.OS === 'ios' ? 'ios-link' : 'md-link'} />
  )
};

LinksStack.path = '';

const SettingsStack = createStackNavigator(
  {
    Settings: SettingsScreen,
  },{
    defaultNavigationOptions: {
      headerTintColor: '#444',
      headerStyle: {
        backgroundColor: 'pink'
      },
      tabBarOptions: {
        style: { backgroundColor: 'orange'}
      }
    }
  },
  config
);

SettingsStack.navigationOptions = {
  tabBarLabel: 'Settings',
  tabBarIcon: ({ focused }) => (
    <TabBarIcon focused={focused} name={Platform.OS === 'ios' ? 'ios-options' : 'md-options'} />
  ),
};

SettingsStack.path = '';


const tabNavigator = createBottomTabNavigator({
  HomeStack,
  LinksStack,
  SettingsStack,
});

tabNavigator.path = '';

export default tabNavigator;

4 个答案:

答案 0 :(得分:2)

我认为您应该将const tabNavigator编辑为

const tabNavigator = createBottomTabNavigator({
  HomeStack,
  LinksStack,
  SettingsStack,
}, {
    defaultNavigationOptions: {
      tabBarOptions: {
        style: { backgroundColor: 'orange'}
      }
    }
});

答案 1 :(得分:0)

@Zelda,请参阅此链接(react-native-tab-view git-hub问题)。

https://github.com/react-native-community/react-native-tab-view/issues/152

答案 2 :(得分:0)

尝试使用它,它可以在Android和iOS上使用 https://github.com/react-navigation/react-navigation/issues/1270#issuecomment-342757336

const tabBarOptions = {
// setting height 'null', and top 0 will change the color of pressed tab
indicatorStyle: {
 height: null,
 top: 0,
 backgroundColor: "red",
 borderBottomColor: "black",
 borderBottomWidth: 3,
},
activeTintColor: "black",
pressColor: "white",
style: {
 backgroundColor: "#ddc8be",
},
labelStyle: { fontSize: 13 },
};

答案 3 :(得分:0)

TabbarOptions 属性包含一个 tabStyle 属性,可帮助您根据需要设置选项卡的样式

const tabBarOPtions = {
          tabStyle: [{backgroundColor: 'red'}]
     }