Added in API level 1
Deprecated in API level 30

TabWidget


open class TabWidget : LinearLayout, View.OnFocusChangeListener
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.LinearLayout
   ↳ android.widget.TabWidget

Displays a list of tab labels representing each page in the parent's tab collection.

The container object for this widget is TabHost. When the user selects a tab, this object sends a message to the parent container, TabHost, to tell it to switch the displayed page. You typically won't use many methods directly on this object. The container TabHost is used to add labels, add the callback handler, and manage callbacks. You might call this object to iterate the list of tabs, or to tweak the layout of the tab list, but most methods should be called on the containing TabHost object.

Summary

XML attributes
android:divider Drawable used to draw the divider between tabs.
android:tabStripEnabled Determines whether the strip under the tab indicators is drawn or not.
android:tabStripLeft Drawable used to draw the left part of the strip underneath the tabs.
android:tabStripRight Drawable used to draw the right part of the strip underneath the tabs.
Inherited XML attributes
Inherited constants
Public constructors
TabWidget(context: Context!)

TabWidget(context: Context!, attrs: AttributeSet!)

TabWidget(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

TabWidget(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open Unit
addView(child: View!)

open Unit

open Unit

open Unit

Sets the current tab and focuses the UI on it.

open CharSequence!

open View!

Returns the tab indicator view at the given index.

open Drawable?

open Drawable?

open Int

Returns the number of tab indicator views.

open Boolean

Indicates whether the bottom strips on the tab indicators are drawn or not.

open Unit
onFocusChange(v: View!, hasFocus: Boolean)

open PointerIcon!
onResolvePointerIcon(event: MotionEvent!, pointerIndex: Int)

open Unit

open Unit

Sets the current tab.

open Unit

Sets the drawable to use as a divider between the tab indicators.

open Unit

Sets the drawable to use as a divider between the tab indicators.

open Unit
setEnabled(enabled: Boolean)

open Unit

Sets the drawable to use as the left part of the strip below the tab indicators.

open Unit

Sets the drawable to use as the left part of the strip below the tab indicators.

open Unit

Sets the drawable to use as the right part of the strip below the tab indicators.

open Unit

Sets the drawable to use as the right part of the strip below the tab indicators.

open Unit
setStripEnabled(stripEnabled: Boolean)

Controls whether the bottom strips on the tab indicators are drawn or not.

Protected methods
open Int
getChildDrawingOrder(childCount: Int, i: Int)

open Unit
onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int)

Inherited functions
Inherited properties

XML attributes

android:divider

android:divider
Drawable used to draw the divider between tabs.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

May be a color value, in the form of "rgb", "argb", "rrggbb", or "aarrggbb".

android:tabStripEnabled

android:tabStripEnabled
Determines whether the strip under the tab indicators is drawn or not.

May be a boolean value, such as "true" or "false".

android:tabStripLeft

android:tabStripLeft
Drawable used to draw the left part of the strip underneath the tabs.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:tabStripRight

android:tabStripRight
Drawable used to draw the right part of the strip underneath the tabs.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

Public constructors

TabWidget

Added in API level 1
TabWidget(context: Context!)

TabWidget

Added in API level 1
TabWidget(
    context: Context!,
    attrs: AttributeSet!)

TabWidget

Added in API level 1
TabWidget(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int)

TabWidget

Added in API level 21
TabWidget(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

Public methods

addView

Added in API level 1
open fun addView(child: View!): Unit

Deprecated: Deprecated in Java.

Parameters
child View!: the child view to add

childDrawableStateChanged

Added in API level 1
open fun childDrawableStateChanged(child: View): Unit

Deprecated: Deprecated in Java.

Parameters
child View: The child whose drawable state has changed. This value cannot be null.

dispatchDraw

Added in API level 1
open fun dispatchDraw(canvas: Canvas): Unit

Deprecated: Deprecated in Java.

Parameters
canvas Canvas: This value cannot be null.

focusCurrentTab

Added in API level 1
open fun focusCurrentTab(index: Int): Unit

Deprecated: Deprecated in Java.

Sets the current tab and focuses the UI on it. This method makes sure that the focused tab matches the selected tab, normally at setCurrentTab. Normally this would not be an issue if we go through the UI, since the UI is responsible for calling TabWidget.onFocusChanged(), but in the case where we are selecting the tab programmatically, we'll need to make sure focus keeps up.

Parameters
index Int: The tab that you want focused (highlighted in orange) and selected (tab brought to the front of the widget)

See Also

getAccessibilityClassName

Added in API level 23
Deprecated in API level 30
open fun getAccessibilityClassName(): CharSequence!

Deprecated: Deprecated in Java.

getChildTabViewAt

Added in API level 4
Deprecated in API level 30
open fun getChildTabViewAt(index: Int): View!

Deprecated: Deprecated in Java.

Returns the tab indicator view at the given index.

Parameters
index Int: the zero-based index of the tab indicator view to return
Return
View! the tab indicator view at the given index

getLeftStripDrawable

Added in API level 24
Deprecated in API level 30
open fun getLeftStripDrawable(): Drawable?

Deprecated: Deprecated in Java.

Return
Drawable? the drawable used as the left part of the strip below the tab indicators, may be null

getRightStripDrawable

Added in API level 24
Deprecated in API level 30
open fun getRightStripDrawable(): Drawable?

Deprecated: Deprecated in Java.

Return
Drawable? the drawable used as the right part of the strip below the tab indicators, may be null

getTabCount

Added in API level 4
Deprecated in API level 30
open fun getTabCount(): Int

Deprecated: Deprecated in Java.

Returns the number of tab indicator views.

Return
Int the number of tab indicator views

isStripEnabled

Added in API level 8
Deprecated in API level 30
open fun isStripEnabled(): Boolean

Deprecated: Deprecated in Java.

Indicates whether the bottom strips on the tab indicators are drawn or not.

onFocusChange

Added in API level 1
open fun onFocusChange(
    v: View!,
    hasFocus: Boolean
): Unit

Deprecated: Deprecated in Java.

Parameters
v View!: The view whose state has changed.
hasFocus Boolean: The new focus state of v.

onResolvePointerIcon

Added in API level 24
Deprecated in API level 30
open fun onResolvePointerIcon(
    event: MotionEvent!,
    pointerIndex: Int
): PointerIcon!

Deprecated: Deprecated in Java.

Parameters
event MotionEvent!: The MotionEvent that requires a pointer icon to be resolved for one of pointers.
pointerIndex Int: The index of the pointer in event for which to retrieve the PointerIcon. This will be between 0 and MotionEvent.getPointerCount().
Return
PointerIcon! the pointer icon to use for specified pointer, or null if a pointer icon is not specified and the default icon should be used.

removeAllViews

Added in API level 1
open fun removeAllViews(): Unit

Deprecated: Deprecated in Java.

setCurrentTab

Added in API level 1
open fun setCurrentTab(index: Int): Unit

Deprecated: Deprecated in Java.

Sets the current tab.

This method is used to bring a tab to the front of the Widget, and is used to post to the rest of the UI that a different tab has been brought to the foreground.

Note, this is separate from the traditional "focus" that is employed from the view logic.

For instance, if we have a list in a tabbed view, a user may be navigating up and down the list, moving the UI focus (orange highlighting) through the list items. The cursor movement does not effect the "selected" tab though, because what is being scrolled through is all on the same tab. The selected tab only changes when we navigate between tabs (moving from the list view to the next tabbed view, in this example).

To move both the focus AND the selected tab at once, please use focusCurrentTab. Normally, the view logic takes care of adjusting the focus, so unless you're circumventing the UI, you'll probably just focus your interest here.

Parameters
index Int: the index of the tab that you want to indicate as the selected tab (tab brought to the front of the widget)

See Also

setDividerDrawable

Added in API level 4
Deprecated in API level 30
open fun setDividerDrawable(drawable: Drawable?): Unit

Deprecated: Deprecated in Java.

Sets the drawable to use as a divider between the tab indicators.

Parameters
divider Drawable that will divide each item.
drawable Drawable?: the divider drawable This value may be null.

setDividerDrawable

Added in API level 4
Deprecated in API level 30
open fun setDividerDrawable(resId: Int): Unit

Deprecated: Deprecated in Java.

Sets the drawable to use as a divider between the tab indicators.

Parameters
resId Int: the resource identifier of the drawable to use as a divider

setEnabled

Added in API level 1
open fun setEnabled(enabled: Boolean): Unit

Deprecated: Deprecated in Java.

Parameters
enabled Boolean: True if this view is enabled, false otherwise.

setLeftStripDrawable

Added in API level 8
Deprecated in API level 30
open fun setLeftStripDrawable(drawable: Drawable?): Unit

Deprecated: Deprecated in Java.

Sets the drawable to use as the left part of the strip below the tab indicators.

Parameters
drawable Drawable?: the left strip drawable This value may be null.

setLeftStripDrawable

Added in API level 8
Deprecated in API level 30
open fun setLeftStripDrawable(resId: Int): Unit

Deprecated: Deprecated in Java.

Sets the drawable to use as the left part of the strip below the tab indicators.

Parameters
resId Int: the resource identifier of the drawable to use as the left strip drawable

setRightStripDrawable

Added in API level 8
Deprecated in API level 30
open fun setRightStripDrawable(drawable: Drawable?): Unit

Deprecated: Deprecated in Java.

Sets the drawable to use as the right part of the strip below the tab indicators.

Parameters
drawable Drawable?: the right strip drawable This value may be null.

setRightStripDrawable

Added in API level 8
Deprecated in API level 30
open fun setRightStripDrawable(resId: Int): Unit

Deprecated: Deprecated in Java.

Sets the drawable to use as the right part of the strip below the tab indicators.

Parameters
resId Int: the resource identifier of the drawable to use as the right strip drawable

setStripEnabled

Added in API level 8
Deprecated in API level 30
open fun setStripEnabled(stripEnabled: Boolean): Unit

Deprecated: Deprecated in Java.

Controls whether the bottom strips on the tab indicators are drawn or not. The default is to draw them. If the user specifies a custom view for the tab indicators, then the TabHost class calls this method to disable drawing of the bottom strips.

Parameters
stripEnabled Boolean: true if the bottom strips should be drawn.

Protected methods

getChildDrawingOrder

Added in API level 1
protected open fun getChildDrawingOrder(
    childCount: Int,
    i: Int
): Int

Deprecated: Deprecated in Java.

Parameters
drawingPosition the drawing order position.
Return
Int the container position of a child for this drawing order position.

onSizeChanged

Added in API level 1
protected open fun onSizeChanged(
    w: Int,
    h: Int,
    oldw: Int,
    oldh: Int
): Unit

Deprecated: Deprecated in Java.

Parameters
w Int: Current width of this view.
h Int: Current height of this view.
oldw Int: Old width of this view.
oldh Int: Old height of this view.