Preview 2.0 is now in Public Beta!
Read the Announcement
Note: You are on the beta version of our docs. This is a work in progress and may contain broken links and pages.

<TabView> is a navigation component that shows content grouped into tabs and lets users switch between tabs.


Simple TabView

xml
 <TabView
   selectedIndex="{{ tabSelectedIndex }}"
   selectedIndexChanged="{{ onSelectedIndexChanged }}"
   androidTabsPosition="bottom"
   androidOffscreenTabLimit="0"
   tabBackgroundColor="#3d5a80"
   tabTextColor="#fff"
   selectedTabTextColor="#eae2b7">
    <TabViewItem title="Profile">
      <StackLayout>
        <Label text="Change Tab" class="text-center text-2xl font-bold pt-4" />
        <Label text="{{ tabSelectedIndexResult }}" class="mt-4 text-center" textWrap="true" />
      </StackLayout>
    </TabViewItem>

    <TabViewItem title="Stats">
      <StackLayout>
        <Label text="Change Tab" class="text-center text-2xl font-bold pt-4" />
        <Label text="{{ tabSelectedIndexResult }}" class="mt-4 text-center" textWrap="true" />
      </StackLayout>
    </TabViewItem>

    <TabViewItem title="Settings">
      <StackLayout>
        <Label text="Change Tab" class="text-center text-2xl font-bold pt-4" />
        <Label text="{{ tabSelectedIndexResult }}" class="mt-4 text-center" textWrap="true" />
      </StackLayout>
    </TabViewItem>
  </TabView>
ts
import {
  Observable,
  SelectedIndexChangedEventData
} from '@nativescript/core'

export class HelloWorldModel extends Observable {
  tabSelectedIndex = 0
  tabSelectedIndexResult = 'Profile Tab (tabSelectedIndex = 0 )'

  ....

  onSelectedIndexChanged(args: SelectedIndexChangedEventData){
    if (args.oldIndex !== -1) {
      const newIndex = args.newIndex

      if (newIndex === 0) {
        this.set('tabSelectedIndexResult', 'Profile Tab (tabSelectedIndex = 0 )')
      } else if (newIndex === 1) {
        this.set('tabSelectedIndexResult', 'Stats Tab (tabSelectedIndex = 1 )')
      } else if (newIndex === 2) {
        this.set('tabSelectedIndexResult', 'Settings Tab (tabSelectedIndex = 2 )')
      }

    }
  }
}

Tip

You can use images for tab icons instead of icon fonts. For more information about how to control the size of icons, see Working with image from resource folders.

Styling

The TabView component has the following unique styling properties:

Props

selectedIndex

xml
 <TabView selectedIndex="{{ tabSelectedIndex }}" />
ts
selectedIndex = tabView.selectedIndex

Gets or sets the currently selected tab. Default is 0.


tabTextColor

xml
<TabView tabTextColor="#fff" />

Corresponding CSS: tab-text-color

css
.tab-view {
  tab-text-color: #fff;
}

Gets or sets the text color of the tabs titles.


tabTextFontSize

Corresponding CSS: tab-text-font-size

css
.tab-view {
  tab-text-font-size: 24;
}

Gets or sets the font size of the tabs titles.


tabBackgroundColor

xml
<TabView tabBackgroundColor="#3d5a80">

Corresponding CSS: tab-background-color

css
.tab-view {
  tab-background-color: #3d5a80;
}

Sets the background color of the tabs.


androidSelectedTabHighlightColor

xml
<TabView androidSelectedTabHighlightColor="#76ABEB">

Corresponding CSS: android-selected-tab-highlight-color

css
.tab-view {
  android-selected-tab-highlight-color: #76abeb;
}

(Android-only)Sets the underline color of the tabs.


androidTabsPosition

xml
 <TabView androidTabsPosition="top" >

Sets the position of the TabView in Android platform.

Valid values: top or bottom. Defaults to top.


iosIconRenderingMode

Gets or sets the icon rendering mode(UIImage.RenderingMode) on iOS.

Defaults to automatic.

Valid values are: automatic| alwaysOriginal| alwaysTemplate


...Inherited

For additional inherited properties, refer to the API Reference.

TabViewItem Props

title

xml
 <TabViewItem title="Profile">

Gets or sets the title of the tab strip entry.


textTransform

xml
<TabViewItem title="Profile" textTransform="capitalize" />

Corresponding CSS: text-transform

css
.tab-view-item {
  text-transform: capitalize;
}

Sets the text transform individually for every TabViewItem. See textTransformType for valid options.


iconSource

xml
 <TabViewItem title="Profile"
 iconSource="~/assets/images/cat.jpeg" >

Gets or sets the icon source of the tab strip entry. Supports local image paths (~), resource images (res://) and icon fonts (font://).

Event(s)

selectedIndexChange

xml
 <TabView loaded="{{ onTabViewLoaded }}" >
ts
onTabViewLoaded(args: EventData){
    const tabView = args.object as TabView

    tabView.on("selectedIndexChanged",(args: SelectedIndexChangedEventData)=>{

    })
  }

Raised when the selected index changes.


SelectedIndexChangedEventData

The SelectedIndexChangedEventData object provides the following data:

NameTypeDescription
oldIndexnumberThe old selected index.
newIndexnumberThe new selected index.

Native component

AndroidiOS
android.support.v4.view.ViewPagerUITabBarController
Previous
Switch