Added in API level 1

android.widget


The widget package contains (mostly visual) UI elements to use on your Application screen. You can also design your own.

To create your own widget, extend View or a subclass. To use your widget in layout XML, there are two additional files for you to create. Here is a list of files you'll need to create to implement a custom widget:

  • Java implementation file - This is the file that implements the behavior of the widget. If you can instantiate the object from layout XML, you will also have to code a constructor that retrieves all the attribute values from the layout XML file.
  • XML definition file - An XML file in res/values/ that defines the XML element used to instantiate your widget, and the attributes that it supports. Other applications will use this element and attributes in their in another in their layout XML.
  • Layout XML [optional]- An optional XML file inside res/layout/ that describes the layout of your widget. You could also do this in code in your Java file.

ApiDemos sample application has an example of creating a custom layout XML tag, LabelView. See the following files that demonstrate implementing and using a custom widget:

  • LabelView.java - The implementation file
  • res/values/attrs.xml - Definition file
  • res/layout/custom_view_1.xml - Layout file

Annotations

RemoteViews.RemoteView This annotation indicates that a subclass of View is allowed to be used with the RemoteViews mechanism. 

Interfaces

AbsListView.MultiChoiceModeListener A MultiChoiceModeListener receives events for AbsListView.CHOICE_MODE_MULTIPLE_MODAL
AbsListView.OnScrollListener Interface definition for a callback to be invoked when the list or grid has been scrolled. 
AbsListView.RecyclerListener A RecyclerListener is used to receive a notification whenever a View is placed inside the RecycleBin's scrap heap. 
AbsListView.SelectionBoundsAdjuster The top-level view of a list item can implement this interface to allow itself to modify the bounds of the selection shown for that item. 
ActionMenuView.OnMenuItemClickListener Interface responsible for receiving menu item click events if the items themselves do not have individual item click listeners. 
Adapter An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. 
AdapterView.OnItemClickListener Interface definition for a callback to be invoked when an item in this AdapterView has been clicked. 
AdapterView.OnItemLongClickListener Interface definition for a callback to be invoked when an item in this view has been clicked and held. 
AdapterView.OnItemSelectedListener Interface definition for a callback to be invoked when an item in this view has been selected. 
Advanceable This interface can be implemented by any collection-type view which has a notion of progressing through its set of children. 
AutoCompleteTextView.OnDismissListener Listener to respond to the AutoCompleteTextView's completion list being dismissed. 
AutoCompleteTextView.Validator This interface is used to make sure that the text entered in this TextView complies to a certain format. 
CalendarView.OnDateChangeListener The callback used to indicate the user changes the date. 
Checkable Defines an extension for views that make them checkable. 
Chronometer.OnChronometerTickListener A callback that notifies when the chronometer has incremented on its own. 
CompoundButton.OnCheckedChangeListener Interface definition for a callback to be invoked when the checked state of a compound button changed. 
DatePicker.OnDateChangedListener The callback used to indicate the user changed the date. 
ExpandableListAdapter An adapter that links a ExpandableListView with the underlying data. 
ExpandableListView.OnChildClickListener Interface definition for a callback to be invoked when a child in this expandable list has been clicked. 
ExpandableListView.OnGroupClickListener Interface definition for a callback to be invoked when a group in this expandable list has been clicked. 
ExpandableListView.OnGroupCollapseListener Used for being notified when a group is collapsed 
ExpandableListView.OnGroupExpandListener Used for being notified when a group is expanded 
Filter.FilterListener

Listener used to receive a notification upon completion of a filtering operation. 

Filterable

Defines a filterable behavior. 

FilterQueryProvider This class can be used by external clients of CursorAdapter and CursorTreeAdapter to define how the content of the adapter should be filtered. 
HeterogeneousExpandableList Additional methods that when implemented make an ExpandableListAdapter take advantage of the Adapter view type mechanism. 
ListAdapter Extended Adapter that is the bridge between a ListView and the data that backs the list. 
MediaController.MediaPlayerControl  
MultiAutoCompleteTextView.Tokenizer  
NumberPicker.Formatter Interface used to format current value into a string for presentation. 
NumberPicker.OnScrollListener Interface to listen for the picker scroll state. 
NumberPicker.OnValueChangeListener Interface to listen for changes of the current value. 
PopupMenu.OnDismissListener Callback interface used to notify the application that the menu has closed. 
PopupMenu.OnMenuItemClickListener Interface responsible for receiving menu item click events if the items themselves do not have individual item click listeners. 
PopupWindow.OnDismissListener Listener that is called when this popup window is dismissed. 
RadioGroup.OnCheckedChangeListener

Interface definition for a callback to be invoked when the checked radio button changed in this group. 

RatingBar.OnRatingBarChangeListener A callback that notifies clients when the rating has been changed. 
RemoteViewsService.RemoteViewsFactory An interface for an adapter between a remote collection view (ListView, GridView, etc) and the underlying data for that view. 
SearchView.OnCloseListener  
SearchView.OnQueryTextListener Callbacks for changes to the query text. 
SearchView.OnSuggestionListener Callback interface for selection events on suggestions. 
SectionIndexer Interface that may implemented on Adapters to enable fast scrolling between sections of an AbsListView
SeekBar.OnSeekBarChangeListener A callback that notifies clients when the progress level has been changed. 
ShareActionProvider.OnShareTargetSelectedListener Listener for the event of selecting a share target. 
SimpleAdapter.ViewBinder This class can be used by external clients of SimpleAdapter to bind values to views. 
SimpleCursorAdapter.CursorToStringConverter This class can be used by external clients of SimpleCursorAdapter to define how the Cursor should be converted to a String. 
SimpleCursorAdapter.ViewBinder This class can be used by external clients of SimpleCursorAdapter to bind values fom the Cursor to views. 
SimpleCursorTreeAdapter.ViewBinder This class can be used by external clients of SimpleCursorTreeAdapter to bind values from the Cursor to views. 
SlidingDrawer.OnDrawerCloseListener Callback invoked when the drawer is closed. 
SlidingDrawer.OnDrawerOpenListener Callback invoked when the drawer is opened. 
SlidingDrawer.OnDrawerScrollListener Callback invoked when the drawer is scrolled. 
SpinnerAdapter Extended Adapter that is the bridge between a Spinner and its data. 
TabHost.OnTabChangeListener Interface definition for a callback to be invoked when tab changed 
TabHost.TabContentFactory Makes the content of a tab when it is selected. 
TextView.OnEditorActionListener Interface definition for a callback to be invoked when an action is performed on the editor. 
ThemedSpinnerAdapter An extension of SpinnerAdapter that is capable of inflating drop-down views against a different theme than normal views. 
TimePicker.OnTimeChangedListener The callback interface used to indicate the time has been adjusted. 
Toolbar.OnMenuItemClickListener Interface responsible for receiving menu item click events if the items themselves do not have individual item click listeners. 
ViewSwitcher.ViewFactory Creates views in a ViewSwitcher. 
WrapperListAdapter List adapter that wraps another list adapter. 
ZoomButtonsController.OnZoomListener Interface that will be called when the user performs an interaction that triggers some action, for example zooming. 

Classes

AbsListView Base class that can be used to implement virtualized lists of items. 
AbsListView.LayoutParams AbsListView extends LayoutParams to provide a place to hold the view type. 
AbsoluteLayout This class was deprecated in API level 3. Use FrameLayout, RelativeLayout or a custom layout instead. 
AbsoluteLayout.LayoutParams Per-child layout information associated with AbsoluteLayout. 
AbsSeekBar AbsSeekBar extends the capabilities of ProgressBar by adding a draggable thumb. 
AbsSpinner An abstract base class for spinner widgets. 
ActionMenuView ActionMenuView is a presentation of a series of menu options as a View. 
ActionMenuView.LayoutParams  
AdapterView<T extends Adapter> An AdapterView is a view whose children are determined by an Adapter
AdapterView.AdapterContextMenuInfo Extra menu information provided to the View.OnCreateContextMenuListener.onCreateContextMenu(ContextMenu, View, ContextMenuInfo) callback when a context menu is brought up for this AdapterView. 
AdapterViewAnimator Base class for a AdapterView that will perform animations when switching between its views. 
AdapterViewFlipper Simple ViewAnimator that will animate between two or more views that have been added to it. 
AlphabetIndexer A helper class for adapters that implement the SectionIndexer interface. 
AnalogClock This class was deprecated in API level 23. This widget is no longer supported; except for RemoteViews use cases like app widgets. 
ArrayAdapter<T> You can use this adapter to provide views for an AdapterView, Returns a view for each object in a collection of data objects you provide, and can be used with list-based user interface widgets such as ListView or Spinner
AutoCompleteTextView

An editable text view that shows completion suggestions automatically while the user is typing. 

BaseAdapter Common base class of common implementation for an Adapter that can be used in both ListView (by implementing the specialized ListAdapter interface) and Spinner (by implementing the specialized SpinnerAdapter interface). 
BaseExpandableListAdapter Base class for a ExpandableListAdapter used to provide data and Views from some data to an expandable list view. 
Button A user interface element the user can tap or click to perform an action. 
CalendarView This class is a calendar widget for displaying and selecting dates. 
CheckBox

A checkbox is a specific type of two-states button that can be either checked or unchecked. 

CheckedTextView An extension to TextView that supports the Checkable interface and displays. 
Chronometer Class that implements a simple timer. 
CompoundButton

A button with two states, checked and unchecked. 

CursorAdapter Adapter that exposes data from a Cursor to a ListView widget. 
CursorTreeAdapter An adapter that exposes data from a series of Cursors to an ExpandableListView widget. 
DatePicker Provides a widget for selecting a date. 
DialerFilter This class was deprecated in API level 26. Use a custom view or layout to handle this functionality instead 
DigitalClock This class was deprecated in API level 17. It is recommended you use TextClock instead. 
EdgeEffect This class performs the graphical effect used at the edges of scrollable widgets when the user scrolls beyond the content bounds in 2D space. 
EditText A user interface element for entering and modifying text. 
ExpandableListView A view that shows items in a vertically scrolling two-level list. 
ExpandableListView.ExpandableListContextMenuInfo Extra menu information specific to an ExpandableListView provided to the View.OnCreateContextMenuListener.onCreateContextMenu(ContextMenu, View, ContextMenuInfo) callback when a context menu is brought up for this AdapterView. 
Filter

A filter constrains data with a filtering pattern. 

Filter.FilterResults

Holds the results of a filtering operation. 

FrameLayout FrameLayout is designed to block out an area on the screen to display a single item. 
FrameLayout.LayoutParams Per-child layout information for layouts that support margins. 
Gallery This class was deprecated in API level 16. This widget is no longer supported. Other horizontally scrolling widgets include HorizontalScrollView and ViewPager from the support library. 
Gallery.LayoutParams Gallery extends LayoutParams to provide a place to hold current Transformation information along with previous position/transformation info. 
GridLayout A layout that places its children in a rectangular grid
GridLayout.Alignment Alignments specify where a view should be placed within a cell group and what size it should be. 
GridLayout.LayoutParams Layout information associated with each of the children of a GridLayout. 
GridLayout.Spec A Spec defines the horizontal or vertical characteristics of a group of cells. 
GridView A view that shows items in two-dimensional scrolling grid. 
HeaderViewListAdapter ListAdapter used when a ListView has header views. 
HorizontalScrollView Layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display. 
ImageButton

Displays a button with an image (instead of text) that can be pressed or clicked by the user. 

ImageSwitcher ViewSwitcher that switches between two ImageViews when a new image is set on it. 
ImageView Displays image resources, for example Bitmap or Drawable resources. 
LinearLayout A layout that arranges other views either horizontally in a single column or vertically in a single row. 
LinearLayout.LayoutParams Per-child layout information associated with ViewLinearLayout. 
ListPopupWindow A ListPopupWindow anchors itself to a host view and displays a list of choices. 
ListView

Displays a vertically-scrollable collection of views, where each view is positioned immediatelybelow the previous view in the list. 

ListView.FixedViewInfo A class that represents a fixed view in a list, for example a header at the top or a footer at the bottom. 
Magnifier Android magnifier widget. 
Magnifier.Builder Builder class for Magnifier objects. 
MediaController A view containing controls for a MediaPlayer. 
MultiAutoCompleteTextView An editable text view, extending AutoCompleteTextView, that can show completion suggestions for the substring of the text where the user is typing instead of necessarily for the entire thing. 
MultiAutoCompleteTextView.CommaTokenizer This simple Tokenizer can be used for lists where the items are separated by a comma and one or more spaces. 
NumberPicker A widget that enables the user to select a number from a predefined range. 
OverScroller This class encapsulates scrolling with the ability to overshoot the bounds of a scrolling operation. 
PopupMenu A PopupMenu displays a Menu in a modal popup window anchored to a View
PopupWindow

This class represents a popup window that can be used to display an arbitrary view. 

ProgressBar

A user interface element that indicates the progress of an operation. 

QuickContactBadge Widget used to show an image with the standard QuickContact badge and on-click behavior. 
RadioButton

A radio button is a two-states button that can be either checked or unchecked. 

RadioGroup

This class is used to create a multiple-exclusion scope for a set of radio buttons. 

RadioGroup.LayoutParams

This set of layout parameters defaults the width and the height of the children to ViewGroup.LayoutParams.WRAP_CONTENT when they are not specified in the XML file. 

RatingBar A RatingBar is an extension of SeekBar and ProgressBar that shows a rating in stars. 
RelativeLayout A Layout where the positions of the children can be described in relation to each other or to the parent. 
RelativeLayout.LayoutParams Specifies how a view is positioned within a RelativeLayout
RemoteViews A class that describes a view hierarchy that can be displayed in another process. 
RemoteViews.DrawInstructions A data parcel that carries the instructions to draw the RemoteViews, as an alternative to XML layout. 
RemoteViews.DrawInstructions.Builder Builder class for DrawInstructions objects. 
RemoteViews.RemoteCollectionItems Representation of a fixed list of items to be displayed in a RemoteViews collection. 
RemoteViews.RemoteCollectionItems.Builder Builder class for RemoteCollectionItems objects. 
RemoteViews.RemoteResponse Class representing a response to an action performed on any element of a RemoteViews. 
RemoteViews.RemoteViewOutlineProvider OutlineProvider for a view with a radius set by RemoteViews.setViewOutlinePreferredRadius(int, float, int)
RemoteViewsService The service to be connected to for a remote adapter to request RemoteViews. 
ResourceCursorAdapter An easy adapter that creates views defined in an XML file. 
ResourceCursorTreeAdapter A fairly simple ExpandableListAdapter that creates views defined in an XML file. 
Scroller

This class encapsulates scrolling. 

ScrollView A view group that allows the view hierarchy placed within it to be scrolled. 
SearchView A widget that provides a user interface for the user to enter a search query and submit a request to a search provider. 
SeekBar A SeekBar is an extension of ProgressBar that adds a draggable thumb. 
ShareActionProvider This is a provider for a share action. 
SimpleAdapter An easy adapter to map static data to views defined in an XML file. 
SimpleCursorAdapter An easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file. 
SimpleCursorTreeAdapter An easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file. 
SimpleExpandableListAdapter An easy adapter to map static data to group and child views defined in an XML file. 
SlidingDrawer This class was deprecated in API level 17. This class is not supported anymore. It is recommended you base your own implementation on the source code for the Android Open Source Project if you must use it in your application. 
Space Space is a lightweight View subclass that may be used to create gaps between components in general purpose layouts. 
Spinner A view that displays one child at a time and lets the user pick among them. 
StackView  
Switch A Switch is a two-state toggle widget. 
TabHost This class was deprecated in API level 30. new applications should use fragment APIs instead of this class: Use TabLayout and ViewPager instead. 
TabHost.TabSpec A tab has a tab indicator, content, and a tag that is used to keep track of it. 
TableLayout

A layout that arranges its children into rows and columns. 

TableLayout.LayoutParams

This set of layout parameters enforces the width of each child to be ViewGroup.LayoutParams.MATCH_PARENT and the height of each child to be ViewGroup.LayoutParams.WRAP_CONTENT, but only if the height is not specified. 

TableRow

A layout that arranges its children horizontally. 

TableRow.LayoutParams

Set of layout parameters used in table rows. 

TabWidget This class was deprecated in API level 30. new applications should use fragment APIs instead of this class: Use TabLayout and ViewPager instead. 
TextClock

TextClock can display the current date and/or time as a formatted string. 

TextSwitcher Specialized ViewSwitcher that contains only children of type TextView
TextView A user interface element that displays text to the user. 
TextView.SavedState User interface state that is stored by TextView for implementing View.onSaveInstanceState
TimePicker A widget for selecting the time of day, in either 24-hour or AM/PM mode. 
Toast A toast is a view containing a quick little message for the user. The toast class helps you create and show those.  
Toast.Callback Callback object to be called when the toast is shown or hidden. 
ToggleButton Displays checked/unchecked states as a button with a "light" indicator and by default accompanied with the text "ON" or "OFF". 
Toolbar A standard toolbar for use within application content. 
Toolbar.LayoutParams Layout information for child views of Toolbars. 
TwoLineListItem This class was deprecated in API level 17. This class can be implemented easily by apps using a RelativeLayout or a LinearLayout. 
VideoView Displays a video file. 
ViewAnimator Base class for a FrameLayout container that will perform animations when switching between its views. 
ViewFlipper Simple ViewAnimator that will animate between two or more views that have been added to it. 
ViewSwitcher ViewAnimator that switches between two views, and has a factory from which these views are created. 
ZoomButton This class was deprecated in API level 26. Use other means to handle this functionality. This widget is merely a simple wrapper around a long-press handler. 
ZoomButtonsController This class was deprecated in API level 26. This functionality and UI is better handled with custom views and layouts rather than a dedicated zoom-control widget 
ZoomControls This class was deprecated in API level 29. This functionality and UI is better handled with custom views and layouts rather than a dedicated zoom-control widget 

Enums

ImageView.ScaleType Options for scaling the bounds of an image to the bounds of this view. 
TextView.BufferType Type of the text buffer that defines the characteristics of the text such as static, styleable, or editable. 

Exceptions

RemoteViews.ActionException Exception to send when something goes wrong executing an action