Skip to content
Titanium SDK
Titanium Docs
Version13.4.1

Titanium.UI.Tab

viewAndroidiPhoneiPadmacOSsince 0.8

Extends Titanium.UI.ViewTitanium.Proxy

A tab instance for a TabGroup.

A TabGroup tab instance. Each tab includes a button and one or more windows, which holds the "contents" of the tab. Users can select a tab by clicking on the tab button.

Use the Titanium.UI.createTab method or <Tab> Alloy element to create a tab.

Use TabGroup.setActiveTab to switch between tabs in a tab group.

The behavior of tabs and tab groups follows the platform's native navigation style, which varies significantly between platforms.

iOS Platform Implementation Notes

On iOS, the tab maintains a stack of windows. Windows on top of the stack can partially or totally obscure windows lower in the stack. Calling open opens a new window on top of the window stack. When a window is closed, either by the user or by code, the window is removed from the stack, making the previous window visible. The root tab window cannot be removed.

On iOS the tab controls are generally kept on screen to allow a user to navigate inside the app. Tab controls are hidden when the user is performing a modal task (for example, composing a message). In this case, the app should provide a button in the navigation bar to return to the previous screen. On iOS, the window should also be opened as modal. On iOS, The tab controls can also be hidden by opening the new window with tabBarHidden set to true.

When closing a tab window in iOS, you should always use the Tab.close method to ensure that the tab group maintains its navigation state.

Android Platform Implementation Notes

On Android, the tab does not maintain a stack of windows. Calling open opens a new, heavyweight window, which by default covers the tab group entirely. This seems quite different from the iOS model, but it is the standard model for Android applications. Users can use the Back button to close the window and return to the tab group.

On Android, tab windows can be closed using either Tab.close or Window.close. Since no window stack is maintained, only a single window opened using Tab.open can be closed using Tab.close.

As on iOS, the root tab window cannot be closed.

Examples

Simple Tab Example

In this example, we create a simple tab and add it to a tab group.

var window = Ti.UI.createWindow({
    title: 'My Tab'
});

var tab = Ti.UI.createTab({
    window: window,
    title: 'My Tab',
    icon: 'myicon.png'
});

tabGroup.addTab(tab);

Alloy XML Markup

Previous example an an Alloy view.

<Alloy>
    <TabGroup id="tabGroup">
        <Tab id="tab" title="My Tab" icon="myicon.png">
            <Window id="window" title="My Tab" />
        </Tab>
      </TabGroup>
</Alloy>

Properties 57

active

BooleaniPhoneiPadmacOS

true if this tab is active, false if it is not.

The tab can be activated by setting the property, but since this property is platform-specific, using TabGroup.setActiveTab is recommended instead.

activeIcon

StringiPhoneiPadmacOSsince 3.1.0

Icon URL for this tab when active.

If unspecified, iOS uses a tint color to indicate the active tab. See icon for more information.

If the icon provided is larger than [30 pixels (60 pixels for retina, 90 pixels for super-retina)] (https://developer.apple.com/ios/human-interface-guidelines/icons-and-images/image-size-and-resolution/), this image will be scaled to fit.

activeIconIsMask

BooleaniPhoneiPadmacOSsince 3.1.3

Defines if the active icon property of the tab must be used as a mask.

This is the equivalent of the iconIsMask property, but for the active icon. When this is true, the active icon is tinted with the color specified in tabsTintColor. When this is false the image is rendered as is, though the title of the tab is still tinted.

Default: true

activeTintColor

Stringsince 9.0.3

Defines the color of the tab icon when it is active.

activeTitleColor

String | Titanium.UI.Colorsince iPhone 4.1.0, iPad 4.1.0, Android 8.0.0

Defines the color of the title of tab when it's active.

The color of the title of the tab when it's active.

apiName

Stringsince Android 3.2.0, iPhone 3.2.0, iPad 3.2.0, macOS 9.2.0read-only

Inherited from Titanium.Proxy

The name of the API that this proxy corresponds to.

backgroundColor

Androidsince 3.0.0

Sets the color of the tab when it is inactive.

For information about color values, see the "Colors" section of Titanium.UI.

badge

Stringsince 9.3.0

Badge value for this tab. null indicates no badge.

On the Android platform you will need to use a Theme with parent="Theme.MaterialComponents.*" in order to use a badge. You have to pass a number as a string. Non-numeric characters will not be displayed.

On iOS, a badge will only be shown if the tab has been assigned an icon. Text only tabs do not support badges.

If this item displays a badge, this color will be used for the badge's background. If set to null, the default background color will be used instead.

For information about color values, see the "Colors" section of Titanium.UI.

badgeColor

String | Titanium.UI.Colordeprecatedsince Android 9.3.0, iPhone 6.1.0, iPad 6.1.0, macOS 9.2.0

Deprecated since 12.2.0

If this item displays a badge, this color will be used for the badge's background. If set to null, the default background color will be used instead.

For information about color values, see the "Colors" section of Titanium.UI.

bubbleParent

Booleansince Android 3.0.0, iPhone 3.0.0, iPad 3.0.0, macOS 9.2.0

Inherited from Titanium.Proxy

Indicates if the proxy will bubble an event to its parent.

Default: true

elevation

NumberAndroidsince 5.0.0Android 5+

Inherited from Titanium.UI.View

Base elevation of the view relative to its parent in pixels.

icon

String

Icon URL for this tab.

iOS Tab Icons

On iOS, tab icons are usually white with a transparent background. The system uses a transparent tint color to indicate whether the tab is active or inactive. In the inactive state, the tint color is based on the tab bar's color tabsBackgroundColor, which defaults to black. In the active state, the tint color is usually blue. Prior to Titanium 3.1, there was no way to override the default active icon tint.

Some icon-related features:

  • You can specify the active tab's tint color as activeTabIconTint.

  • You can set separate icon images for the active and inactive states. If activeIcon is set, then icon is used in the inactive state, and activeIcon is used in the active state. No default tint is applied to either icon.

If the icon provided is larger than [30 pixels (60 pixels for retina, 90 pixels for super-retina)] (https://developer.apple.com/ios/human-interface-guidelines/icons-and-images/image-size-and-resolution/), this image will be scaled to fit if used with activeIcon, and cropped at the bottom otherwise.

Android Tab Icons

Can be used in combination with iconFamily in a BottomNavigation setup with experimental:true.

iconFamily

StringAndroidsince 12.7.0

Specifies the font family or specific font to use.

When using a BottomNavigation setup with experimental:true you can use this property in combination with an icon to use an icon-font for the tab icons:

'#tab1': {
  icon: "\ueac1",
  iconFamily: "tabler-icons"
}

iconInsets

TabIconInsetsiPhoneiPadmacOSsince 5.2.0

The icon inset or outset for each edge.

Use this property for example to center an icon without providing a title. To do that, set the insets to { top: 6 } and/or { left: 6 }. The right and bottom are calculated internally to prevent the icon from mutating.

Default: All insets are zero.

iconIsMask

BooleaniPhoneiPadmacOSsince 3.1.3

Defines if the icon property of the tab must be used as a mask.

When this property is true, the color data of the image specified as the icon is ignored and the image is used as an alpha mask. When this is false, the color data of the image is preserved.

Default: true

rotation

NumberAndroidiPhoneiPadsince Android 5.4.0, iPhone 12.3.0, iPad 12.3.0

Inherited from Titanium.UI.View

Clockwise 2D rotation of the view in degrees.

tintColor

Stringsince iPhone 3.1.3, iPad 3.1.3, Android 9.0.3

Defines the color of the tab icon.

title

String

Title for this tab.

titleColor

String | Titanium.UI.Colorsince iPhone 4.1.0, iPad 4.1.0, Android 8.0.0

Defines the color of the title of tab when it's inactive.

The color of the title of the tab when it's inactive.

titleid

String

Key identifying a string from the locale file to use for the tab title. Only one of title or titleid should be specified.

tooltip

Stringsince 12.1.0iOS 15.0+

Inherited from Titanium.UI.View

The default text to display in the control's tooltip.

touchFeedback

BooleanAndroidsince 6.1.0

Inherited from Titanium.UI.View

A material design visual construct that provides an instantaneous visual confirmation of touch point.

Default: false

translationX

NumberAndroidsince 5.0.0

Inherited from Titanium.UI.View

Horizontal location of the view relative to its left position in pixels.

Methods 14

Inherited from Titanium.Proxy

Adds the specified callback as an event listener for the named event.

Parameters
ParametersTypeDescription
nameString

Name of the event.

callbackCallback<Titanium.Event>

Callback function to invoke when the event is fired.

4 fields
bubbles Boolean

True if the event will try to bubble up if possible.

cancelBubble Boolean

Set to true to stop the event from bubbling.

source Object

Source object that fired the event.

type String

Name of the event fired.

Closes the top-level window for this tab.

On iOS, this method should be used when closing a window opened from a tab, to correctly maintain the iOS tab group's navigation state. Note that the window to be closed must be passed in as a parameter:

myTab.close(tabWin);

On Android, this method does not take a window parameter.

myTab.close();

On Android, if a window has been opened in front of the tab using Tab.open, a subsequent call to Tab.close is equivalent to calling close on that window. No window stack is maintained, so only the most-recently opened window on a given tab can be closed in this way.

All platforms accept an optional options parameter. The only supported property for this dictionary is the animated flag, which specifies whether the window close should be animated. animated is true by default.

Parameters
ParametersTypeDescription
windowTitanium.UI.Window

Window to close. This parameter must be omitted on Android.

options?Object

Dictionary of display and animation settings to use when closing the window. Identical to the options parameter to Window.close. iOS only supports the animated parameter.

convertPointToView

since Android 1.8, iPhone 1.8, iPad 1.8, macOS 9.2.0

Inherited from Titanium.UI.View

Translates a point from this view's coordinate system to another view's coordinate system.

Parameters
ParametersTypeDescription
pointPoint

A point in this view's coordinate system.

If this argument is missing an x or y property, or the properties can not be converted into numbers, an exception will be raised.

destinationViewTitanium.UI.View

View that specifies the destination coordinate system to convert to. If this argument is not a view, an exception will be raised.

Returns Point

Inherited from Titanium.Proxy

Fires a synthesized event to any registered listeners.

Parameters
ParametersTypeDescription
nameString

Name of the event.

event?Dictionary

A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.

getViewById

since 6.1.0

Inherited from Titanium.UI.View

Returns the matching view of a given view ID.

Parameters
ParametersTypeDescription
idString

The ID of the view that should be returned. Use the id property in your views to enable it for indexing in this method.

insertAt

since 3.3.0

Inherited from Titanium.UI.View

Inserts a view at the specified position in the children array.

Parameters
ParametersTypeDescription
paramsViewPositionOptions

Pass an object that specifies the view to insert and optionally at which position (defaults to end)

2 fields
position? Number

Position in the children array of the view element to replace.

view Titanium.UI.View

View to insert. Required.

Opens a new window.

On iOS, the new window is opened as the top window in the tab's window stack. On Android, the new window is opened as a new, heavyweight window, obscuring the tab group.

Parameters
ParametersTypeDescription
windowTitanium.UI.Window

Window to open.

options?openWindowParams

Dictionary of display and animation settings to use when opening the window. Identical to the options parameter to Window.open. iOS only supports the animated parameter.

popToRootWindow

since Android 12.7.0, iPhone 6.2.0, iPad 6.2.0, macOS 9.2.0

Closes all windows that are currently opened inside the tab.

Note that only the close event of the most recently opened window is fired.

Parameters
ParametersTypeDescription
options?AnimatedOptions

iOS only: Options supporting a single animated boolean property to determine whether the windows will be animated while being closed (default: false).

Inherited from Titanium.Proxy

Removes the specified callback as an event listener for the named event.

Parameters
ParametersTypeDescription
nameString

Name of the event.

callbackCallback<Titanium.Event>

Callback function to remove. Must be the same function passed to addEventListener.

4 fields
bubbles Boolean

True if the event will try to bubble up if possible.

cancelBubble Boolean

Set to true to stop the event from bubbling.

source Object

Source object that fired the event.

type String

Name of the event fired.

setWindow

deprecated

Deprecated since 10.0.0

Set the value of the window property directly.

Sets the root window that appears in the tab.

You can only use this method to set the tab's root window before the TabGroup containing this tab is opened, that is, once the TabGroup is displayed, you cannot change the root window that appears in the tab.

Parameters
ParametersTypeDescription
windowTitanium.UI.Window

Root window of the tab.

Inherited from Titanium.UI.View

Returns an image of the rendered view, as a Blob.

Parameters
ParametersTypeDescription
callback?Callback<Titanium.Blob>

Function to be invoked upon completion. If non-null, this method will be performed asynchronously. If null, it will be performed immediately.

honorScaleFactor?Boolean

Determines whether the image is scaled based on scale factor of main screen. (iOS only)

When set to true, image is scale factor is honored. When set to false, the image in the blob has the same dimensions for retina and non-retina devices.

Events 15

click

Android

Fired when this tab is clicked in the tab group.

Inherited from Titanium.UI.View

Fired when the device detects a double click against the view.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

obscuredBoolean

Returns true if the double click passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

Inherited from Titanium.UI.View

Fired when the device detects a double tap against the view.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

obscuredBoolean

Returns true if the double tap passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

Inherited from Titanium.UI.View

Fired when the device detects a long press.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

obscuredBoolean

Returns true if the long press passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

rotate

since 12.7.0

Inherited from Titanium.UI.View

Fired when the device detects a two finger rotation.

Event properties
Event propertiesTypeDescription
rotateNumber

Rotation in degrees.

selected

since Android 3.5.1, iPhone 5.2.0, iPad 5.2.0

Fired when the tab is selected.

Event properties
Event propertiesTypeDescription
indexNumber

Index of the current active tab.

previousIndexNumber

Index of the previous active tab.

tabTitanium.UI.Tab

Current active tab object.

previousTabTitanium.UI.Tab

Previous active tab object.

Inherited from Titanium.UI.View

Fired when the device detects a single tap against the view.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

obscuredBoolean

Returns true if the single tap passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

Inherited from Titanium.UI.View

Fired when the device detects a swipe gesture against the view.

Event properties
Event propertiesTypeDescription
directionString

Direction of the swipe--either 'left', 'right', 'up', or 'down'.

xNumber

X coordinate of the event's endpoint from the source view's coordinate system.

yNumber

Y coordinate of the event's endpoint from the source view's coordinate system.

obscuredBoolean

Returns true if the swipe passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

Inherited from Titanium.UI.View

Fired when a touch event is interrupted by the device.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

forceNumber

The current force value of the touch event. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later and on some Android devices.

sizeNumber

The current size of the touch area. Note: This property is only available on some Android devices.

maximumPossibleForceNumber

Maximum possible value of the force property. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later.

altitudeAngleNumber

A value which indicates the stylus angle on the screen. If the stylus is perpendicular to the screen or no stylus is being used, the value will be Pi/2. If the stylus is parallel to the screen, the value will be 0. Note: This property is only available for iOS devices that support 3D-Touch and are 9.1 or later.

timestampNumber

The time (in seconds) when the touch was used in correlation with the system start up. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later.

azimuthUnitVectorInViewXNumber

The x value of the unit vector that points in the direction of the azimuth of the stylus. Note: This property is only available for iOS devices that support the Apple Pencil and are 9.1 or later.

azimuthUnitVectorInViewYNumber

The y value of the unit vector that points in the direction of the azimuth of the stylus. Note: This property is only available for iOS devices that support the Apple Pencil and are 9.1 or later.

obscuredBoolean

Returns true if the touch passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

Inherited from Titanium.UI.View

Fired when a touch event is completed.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

forceNumber

The current force value of the touch event. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later and on some Android devices.

sizeNumber

The current size of the touch area. Note: This property is only available on some Android devices.

maximumPossibleForceNumber

Maximum possible value of the force property. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later.

altitudeAngleNumber

A value which indicates the stylus angle on the screen. If the stylus is perpendicular to the screen or no stylus is being used, the value will be Pi/2. If the stylus is parallel to the screen, the value will be 0. Note: This property is only available for iOS devices that support 3D-Touch and are 9.1 or later.

timestampNumber

The time (in seconds) when the touch was used in correlation with the system start up. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later.

azimuthUnitVectorInViewXNumber

The x value of the unit vector that points in the direction of the azimuth of the stylus. Note: This property is only available for iOS devices that support the Apple Pencil and are 9.1 or later.

azimuthUnitVectorInViewYNumber

The y value of the unit vector that points in the direction of the azimuth of the stylus. Note: This property is only available for iOS devices that support the Apple Penciland are 9.1 or later.

obscuredBoolean

Returns true if the touch passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

Inherited from Titanium.UI.View

Fired as soon as the device detects movement of a touch.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

forceNumber

The current force value of the touch event. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later and on some Android devices.

sizeNumber

The current size of the touch area. Note: This property is only available on some Android devices.

maximumPossibleForceNumber

Maximum possible value of the force property. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later.

altitudeAngleNumber

A value which indicates the stylus angle on the screen. If the stylus is perpendicular to the screen or no stylus is being used, the value will be Pi/2. If the stylus is parallel to the screen, the value will be 0. Note: This property is only available for iOS devices that support 3D-Touch and are 9.1 or later.

timestampNumber

The time (in seconds) when the touch was used in correlation with the system start up. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later.

azimuthUnitVectorInViewXNumber

The x value of the unit vector that points in the direction of the azimuth of the stylus. Note: This property is only available for iOS devices that support the Apple Pencil and are 9.1 or later.

azimuthUnitVectorInViewYNumber

The y value of the unit vector that points in the direction of the azimuth of the stylus. Note: This property is only available for iOS devices that support the Apple Pencil and are 9.1 or later.

obscuredBoolean

Returns true if the touch passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

Inherited from Titanium.UI.View

Fired as soon as the device detects a touch gesture.

Event properties
Event propertiesTypeDescription
xNumber

X coordinate of the event from the source view's coordinate system.

yNumber

Y coordinate of the event from the source view's coordinate system.

forceNumber

The current force value of the touch event. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later and on some Android devices.

sizeNumber

The current size of the touch area. Note: This property is only available on some Android devices.

maximumPossibleForceNumber

Maximum possible value of the force property. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later.

altitudeAngleNumber

A value which indicates the stylus angle on the screen. If the stylus is perpendicular to the screen or no stylus is being used, the value will be Pi/2. If the stylus is parallel to the screen, the value will be 0. Note: This property is only available for iOS devices that support 3D-Touch and are 9.1 or later.

timestampNumber

The time (in seconds) when the touch was used in correlation with the system start up. Note: This property is only available for iOS devices that support 3D-Touch and run 9.0 or later.

azimuthUnitVectorInViewXNumber

The x value of the unit vector that points in the direction of the azimuth of the stylus. Note: This property is only available for iOS devices that support the Apple Pencil and are 9.1 or later.

azimuthUnitVectorInViewYNumber

The y value of the unit vector that points in the direction of the azimuth of the stylus. Note: This property is only available for iOS devices that support the Apple Pencil and are 9.1 or later.

obscuredBoolean

Returns true if the touch passed through an overlapping window belonging to another app.

This is a security feature to protect an app from "tapjacking", where a malicious app can use a system overlay to intercept touch events in your app or to trick the end-user to tap on UI in your app intended for the overlay.

unselected

since Android 3.5.1, iPhone 5.2.0, iPad 5.2.0

Fired when the tab is no longer selected.

Event properties
Event propertiesTypeDescription
indexNumber

Index of the current active tab.

previousIndexNumber

Index of the previous active tab.

tabTitanium.UI.Tab

Current active tab object.

previousTabTitanium.UI.Tab

Previous active tab object.