【问题标题】:changing background color of react native tabBar改变反应原生tabBar的背景颜色
【发布时间】:2020-05-20 12:21:23
【问题描述】:

所以我真的是反应原生和移动开发的新手, 我想更改底部标签栏导航的背景颜色,但我似乎不知道该怎么做,因为我从一个带有导航的 react native 项目开始(世博会初始化阶段的选项),东西是如何写的与我在网上看到的不同,我知道我需要添加

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

但老实说,我知道确切的位置,如果有人可以提供帮助,将不胜感激! 这是我的代码:

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;

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

        尝试使用它,它适用于 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 },
        };
        

        【讨论】:

          【解决方案4】:

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

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

          【讨论】:

          • 你应该在你的答案中添加一些文字,解释你的答案为什么以及如何解决手头的问题
          【解决方案5】:

          将此用于 React Navigation 版本 6.x

          screenOptions={{
                  tabBarStyle: {
                    backgroundColor: '#00bcd4',
                  },
                }}
          

          【讨论】:

            猜你喜欢
            • 2022-11-12
            • 1970-01-01
            • 2021-02-28
            • 2015-04-05
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-05-04
            相关资源
            最近更新 更多