2017-08-05 135 views
0

我想改變我的活動標籤標題顏色,我嘗試過使用tabBarOptions,但它只是不會工作,我做錯了什麼? 這是我的代碼:無法更改標籤欄標籤的顏色

Home:{ 
screen: TabNavigator({ 
    Home: { 
    screen: HomeScreen, 
    navigationOptions: ({ navigation }) => ({ 
     title: 'Home', 
     tabBarIcon: ({ tintColor, focused }) => (
     <Ionicons 
     name={focused ? 'ios-home' : 'ios-home-outline'} 
     size={26} 
     style={{ color: focused ? `${tabBarColor}` : tintColor}} 
     /> 
    ), 
     header: null, 
    }), 
    }, 
    Profile: { 
    screen: ProfileScreen, 
    navigationOptions: ({ navigation }) => ({ 
     title: 'Profile', 
     tabBarIcon: ({ tintColor, focused }) => (
     <Ionicons 
     name={focused ? 'ios-people' : 'ios-people-outline'} 
     size={26} 
     style={{ color: focused ? `${tabBarColor}` : tintColor }} 
     /> 
    ), 
     header: null, 
    }), 
    }, 
}), 
tabBarOptions:{ 
    activeTintColor: `${tabBarColor}`, 
} 
} 

我讀我的文檔和搜索的例子,但找不到任何爲我工作。 這就像應用程序只是忽略tabBarOptions。

在此先感謝!

回答

0

看起來像從文檔改變tabBarLabel 風格,你 需要提供自定義組件基於集中tabBarLabel道具和更新。

嘗試一下本作MyTabBarLabel組件

navigationOptions:() => ({ 
    tabBarLabel: ({focused}) => <MyTabBarLabel title={i18n.t('common.request')} focused={focused} />, 
    tabBarIcon: ({focused}) => <MyTabBarIcon icon='requests' focused={focused}/> 
}) 

export default function MyTabBarLabel (props) { 

    return (
    <WFText style={[styles.tabBarLabel, props.focused? styles.tabBarLabelActive : {}]} >{props.title}</WFText> 
); 
} 

const styles = StyleSheet.create({ 
    tabBarLabel: { 
    paddingBottom: 6, 
    fontSize: 10, 
    textAlign: 'center' 
    }, 
    tabBarLabelActive: { 
    color: 'red' 
    } 
}); 

替換你的組件到位MyTabBarLabel和MyTabBarIcon的

參見: https://reactnavigation.org/docs/navigators/tab#Screen-Navigation-Options

+0

首先,謝謝:D,我應該在哪裏添加它?你在哪裏找到這個文檔?我現在再次看着文檔,在那裏看不到它。 –

+0

我已經添加了參考現在檢查 –

+0

謝謝,但我仍然可以在那裏看到tabBarOptions解決方案,你確定它改變了嗎?我也不知道應該在哪裏添加解決方案。 –