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!)

Adds a child view.

open Unit

If addStatesFromChildren is true, refreshes this group's drawable state (to include the states from its children).

open Unit

Called by draw to draw the child views.

open Unit

Sets the current tab and focuses the UI on it.

open CharSequence!

Return the class name of this object to be used for accessibility purposes.

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)

Called when the focus state of a view has changed.

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

Resolve the pointer icon that should be used for specified pointer in the motion event.

open Unit

Call this method to remove all child views from the ViewGroup.

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)

Set the enabled state of this view.

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)

Converts drawing order position to container position.

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

This is called during layout when the size of this view has changed.

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.

Adds a child view. If no layout parameters are already set on the child, the default parameters for this ViewGroup are set on the child.

Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.

Parameters
child View!: the child view to add

childDrawableStateChanged

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

Deprecated: Deprecated in Java.

If addStatesFromChildren is true, refreshes this group's drawable state (to include the states from its children).

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.

Called by draw to draw the child views. This may be overridden by derived classes to gain control just before its children are drawn (but after its own view has been drawn).

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.

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.

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.

Called when the focus state of a view has changed.

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.

Resolve the pointer icon that should be used for specified pointer in the motion event. The default implementation will resolve the pointer icon to one set using setPointerIcon(android.view.PointerIcon) for mouse devices. Subclasses may override this to customize the icon for the given pointer. For example, to always show the PointerIcon.TYPE_HANDWRITING icon for a stylus pointer, the event can be resolved in the following way:

@Override
  public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
      final int toolType = event.getToolType(pointerIndex);
      if (!event.isFromSource(InputDevice.SOURCE_MOUSE)
              && event.isFromSource(InputDevice.SOURCE_STYLUS)
              && (toolType == MotionEvent.TOOL_TYPE_STYLUS
                      || toolType == MotionEvent.TOOL_TYPE_ERASER)) {
          // Show this pointer icon only if this pointer is a stylus.
          return PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_HANDWRITING);
      }
      // Use the default logic for determining the pointer icon for other non-stylus pointers,
      // like for the mouse cursor.
      return super.onResolvePointerIcon(event, pointerIndex);
  }
  

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.

Call this method to remove all child views from the ViewGroup.

Note: do not invoke this method from draw(android.graphics.Canvas), onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.

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.

Set the enabled state of this view. The interpretation of the enabled state varies by subclass.

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.

Converts drawing order position to container position. Override this if you want to change the drawing order of children. By default, it returns drawingPosition.

NOTE: In order for this method to be called, you must enable child ordering first by calling setChildrenDrawingOrderEnabled(boolean).

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.

This is called during layout when the size of this view has changed. If you were just added to the view hierarchy, you're called with the old values of 0.

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.