Android 自定义本机基的选项卡

Android 自定义本机基的选项卡,android,ios,react-native,tabs,native-base,Android,Ios,React Native,Tabs,Native Base,我需要在react本机应用程序中从本机基础自定义选项卡(更改其背景颜色),如图所示 我已经尝试过这个style={{{backgroundColor:'#c0c0'}}但是我一直得到默认的主题 您可以将自己的样式应用于本机基本选项卡,如下所示 <Tabs tabBarUnderlineStyle={{borderBottomWidth:2}}> <Tab heading="Popular" tabStyle={{backgroundColor: 'red'}} text

我需要在react本机应用程序中从本机基础自定义选项卡(更改其背景颜色),如图所示


我已经尝试过这个
style={{{backgroundColor:'#c0c0'}}
但是我一直得到默认的主题

您可以将自己的样式应用于本机基本选项卡,如下所示

<Tabs tabBarUnderlineStyle={{borderBottomWidth:2}}>
    <Tab heading="Popular" tabStyle={{backgroundColor: 'red'}} textStyle={{color: '#fff'}} activeTabStyle={{backgroundColor: 'red'}} activeTextStyle={{color: '#fff', fontWeight: 'normal'}}>
        // tab content
    </Tab>
    <Tab heading="Popular" tabStyle={{backgroundColor: 'red'}} textStyle={{color: '#fff'}} activeTabStyle={{backgroundColor: 'red'}} activeTextStyle={{color: '#fff', fontWeight: 'normal'}}>
        // tab content
    </Tab>
</Tabs>

//选项卡内容
//选项卡内容

如果您使用的组件带有
选项卡标题
而不是
字符串标题,则使用
选项卡样式
选项卡上的
文本样式
道具或
选项卡标题
将不起作用(至少到目前为止)。您必须手动设置
选项卡标题
图标
文本的样式

这里有一个例子-

这行不通 如果要切换活动选项卡样式
this.setState({currentTab:i})}>
//选项卡内容
//选项卡内容
我试过了☝ 解决方案<太糟糕了(在我看来)

所以我选择了原来的答案,并决定在我的标签标题中没有图标(这比处理状态更改延迟更划算)

我还注意到他们有
标签样式
和其他
道具
用于
标签标题
,所以他们可能正在研究它,而这只是目前的一个bug


无论如何,我只想指出这一点。

请注意,如果您在选项卡组件的renderTabBar方法中使用ScrollableTab,那么上面的示例是部分解决方案,因为您必须在选项卡和选项卡组件的嵌套组件上应用所需的样式。因此,如果您使用的是ScrollableTab组件,我建议您直接将样式应用于ScrollableTab组件。检查以下示例:

}>
您的选项卡内容
有关更多参考信息,请参见尝试:

<ScrollableTab style={{borderBottomWidth: 0, backgroundColor: 'some_color'}} 
/>
tabBarUnderlineStyle={{backgroundColor: '#eff2f8'}}

感谢Aswin Ramakrishnan的回答,只是修改了一点:)

如果需要活动选项卡样式切换(用于循环)
this.setState({currentTab:i})
>
{dataArray.map((项,键)=>{
返回(
{此._renderContent(项目)}
);
})}
;
我试过了☝ 解决方案它对我有用


您可以通过以下方式实现:

<Tabs initialPage={this.state.index} 
            tabBarBackgroundColor='#fff'
            headerTintColor= '#fff'
            tabBarUnderlineStyle = {{backgroundColor: navigationColor}}
            tabBarPosition="top"
            onChangeTab={({ i }) => this.updateTabIndex(i)}
            >
                <Tab
                    heading={
                    <TabHeading style={{backgroundColor: '#fff'}}>
                        <Image source = {require('../../assets/Images/icon.png')} 
                        style = {styles.tabIcon}/>
                    </TabHeading>}
                >
                </Tab>
</Tabs>
this.updateTabIndex(i)}
>

谢谢,它几乎解决了我的问题。。我编辑了我的问题,所以你能帮我再核对一下吗。。事实上,我需要把所有的颜色都变成红色,而不仅仅是当它是红色的时候active@IrfanAli嘿,我无法更改选项卡的背景色。我已经尝试了你的代码,但不幸的是似乎没有任何工作,标签仍然有一个蓝色的背景。有什么建议吗?或者API中有变化吗?他们排除了native base 2.1.4中的react native scrollable tab view依赖项。只有当并且仅当您使用string heading
heading=“head”
时,这才会起作用。如果您使用的是像
heading={…}
这样的组件,它根本不会起作用。如何更改指示器颜色?谢谢。在这件蠢事上浪费了几个小时。NativeBase确实需要加强文档编制。只有在使用可滚动选项卡时才会出现延迟(一种小故障)
<ScrollableTab style={{borderBottomWidth: 0, backgroundColor: 'some_color'}} 
/>
<TabHeading style={{
                backgroundColor: 'some_color',
                borderBottomWidth: 0,
}}>
tabBarUnderlineStyle={{backgroundColor: '#eff2f8'}}
<Tabs
  tabBarUnderlineStyle={{ borderBottomWidth: 2 }}
  initialPage={this.state.currentTab}
  onChangeTab={({ i }) => this.setState({ currentTab: i })}
>
  {dataArray.map((item, key) => {
    return (
      <Tab
        tabStyle={{
          backgroundColor: Colors.defaultColor,
          color: Colors.grayText
        }}
        activeTabStyle={{
          backgroundColor: Colors.defaultColor
        }}
        heading={
          <TabHeading
            textStyle={styles.inactiveTextStyle}
            style={
              this.state.currentTab === key
                ? styles.activeTabStyle
                : styles.inactiveTabStyle
            }
          >
            <Text
              style={
                this.state.currentTab === key
                  ? styles.activeTextStyle
                  : styles.inactiveTextStyle
              }
            >
              {item.title}
            </Text>
          </TabHeading>
        }
      >
        {this._renderContent(item)}
      </Tab>
    );
  })}
</Tabs>;
<Tabs initialPage={this.state.index} 
            tabBarBackgroundColor='#fff'
            headerTintColor= '#fff'
            tabBarUnderlineStyle = {{backgroundColor: navigationColor}}
            tabBarPosition="top"
            onChangeTab={({ i }) => this.updateTabIndex(i)}
            >
                <Tab
                    heading={
                    <TabHeading style={{backgroundColor: '#fff'}}>
                        <Image source = {require('../../assets/Images/icon.png')} 
                        style = {styles.tabIcon}/>
                    </TabHeading>}
                >
                </Tab>
</Tabs>