android - 如何将 LinearGradient 用于反应选项卡导航器选项卡
问题描述
我有一个反应tabnavigator
,我从ReactNavigation(v2)
组件中使用它:
const Tab = createMaterialTopTabNavigator({
Nearest: {
screen: Nearest, navigationOptions: {
tabBarLabel: 'myprofile'
}
},
Recomanded: {
screen: Recomanded, navigationOptions: {
tabBarLabel: 'recomanded'
}
},
Home: {
screen: Hotest, navigationOptions: {
tabBarLabel: 'hotest'
}
},
},
{
tabBarOptions: {
labelStyle: {
fontSize: 12,
fontFamily:"IRANSans"
},
tabStyle: {
backgroundColor: '#ef6102',
}
}
}
);
现在我想对标签颜色使用线性渐变,但我找不到任何方法!...这怎么可能?我如何获取此标签内的标签:
<LinearGradient colors={['#EF7D2F', '#C8191A']}>..here..</LinearGradient>
解决方案
您应该使用以下方法为您的选项卡添加自定义视图tabBarCompontent
:
const Tab = createMaterialTopTabNavigator({
Nearest: {
screen: Nearest, navigationOptions: {
tabBarLabel: 'myprofile'
}
},
Recomanded: {
screen: Recomanded, navigationOptions: {
tabBarLabel: 'recomanded'
}
},
Home: {
screen: Hotest, navigationOptions: {
tabBarLabel: 'hotest'
}
},
},
{
tabBarComponent:(props)=>{
return(<TabBar {...props}></TabBar>)},<<<<<<<look here<<<<<<<<
tabBarOptions: {
labelStyle: {
fontSize: 12,
fontFamily:"IRANSans"
},
tabStyle: {
backgroundColor: '#ef6102',
}
}
}
);
例如 TabBar 是一个像这样的组件:
const TabBar=(props)=> {
return (
<LinearGradient colors={['#EF7D2F', '#C8191A']}>..here..
</LinearGradient>
);
}
您可以将此作为参考
推荐阅读
- random - OCaml 中的随机数生成
- python - ModuleNotFoundError:但仅在我在 pycharm 中启动调试器时出现
- php - Laravel 验证 url 名称
- gmail-api - Google 登录错误 - API_UNAVAILABLE 在 Gmail 帐户上请求 Gmail 范围
- javascript - 当在 JavaScript 中创建复选框时得到 [object HTMLInputElement]
- azure-devops - Azure 构建管道 - 发布的 zip 文件
- python - 如何通过 Selenium 和 Python 在表格中单击 onclick 事件
- javascript - 计数器达到 0 或复位后的清除间隔
- python - 从输入字符串确定是否为 json_newline 格式
- java - 在我的活动启动开始时滞后