Most visited

Recently visited

Added in API level 1

View

public class View
extends Object implements Drawable.Callback, KeyEvent.Callback, AccessibilityEventSource

java.lang.Object
   ↳ android.view.View
Known Direct Subclasses
Known Indirect Subclasses


This class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.). The ViewGroup subclass is the base class for layouts, which are invisible containers that hold other Views (or other ViewGroups) and define their layout properties.

Developer Guides

For information about using this class to develop your application's user interface, read the User Interface developer guide.

Using Views

All of the views in a window are arranged in a single tree. You can add views either from code or by specifying a tree of views in one or more XML layout files. There are many specialized subclasses of views that act as controls or are capable of displaying text, images, or other content.

Once you have created a tree of views, there are typically a few types of common operations you may wish to perform:

Note: The Android framework is responsible for measuring, laying out and drawing views. You should not call methods that perform these actions on views yourself unless you are actually implementing a ViewGroup.

Implementing a Custom View

To implement a custom view, you will usually begin by providing overrides for some of the standard methods that the framework calls on all views. You do not need to override all of these methods. In fact, you can start by just overriding onDraw(android.graphics.Canvas).

Category Methods Description
Creation Constructors There is a form of the constructor that are called when the view is created from code and a form that is called when the view is inflated from a layout file. The second form should parse and apply any attributes defined in the layout file.
onFinishInflate() Called after a view and all of its children has been inflated from XML.
Layout onMeasure(int, int) Called to determine the size requirements for this view and all of its children.
onLayout(boolean, int, int, int, int) Called when this view should assign a size and position to all of its children.
onSizeChanged(int, int, int, int) Called when the size of this view has changed.
Drawing onDraw(android.graphics.Canvas) Called when the view should render its content.
Event processing onKeyDown(int, KeyEvent) Called when a new hardware key event occurs.
onKeyUp(int, KeyEvent) Called when a hardware key up event occurs.
onTrackballEvent(MotionEvent) Called when a trackball motion event occurs.
onTouchEvent(MotionEvent) Called when a touch screen motion event occurs.
Focus onFocusChanged(boolean, int, android.graphics.Rect) Called when the view gains or loses focus.
onWindowFocusChanged(boolean) Called when the window containing the view gains or loses focus.
Attaching onAttachedToWindow() Called when the view is attached to a window.
onDetachedFromWindow() Called when the view is detached from its window.
onWindowVisibilityChanged(int) Called when the visibility of the window containing the view has changed.

IDs

Views may have an integer id associated with them. These ids are typically assigned in the layout XML files, and are used to find specific views within the view tree. A common pattern is to:

View IDs need not be unique throughout the tree, but it is good practice to ensure that they are at least unique within the part of the tree you are searching.

Position

The geometry of a view is that of a rectangle. A view has a location, expressed as a pair of left and top coordinates, and two dimensions, expressed as a width and a height. The unit for location and dimensions is the pixel.

It is possible to retrieve the location of a view by invoking the methods getLeft() and getTop(). The former returns the left, or X, coordinate of the rectangle representing the view. The latter returns the top, or Y, coordinate of the rectangle representing the view. These methods both return the location of the view relative to its parent. For instance, when getLeft() returns 20, that means the view is located 20 pixels to the right of the left edge of its direct parent.

In addition, several convenience methods are offered to avoid unnecessary computations, namely getRight() and getBottom(). These methods return the coordinates of the right and bottom edges of the rectangle representing the view. For instance, calling getRight() is similar to the following computation: getLeft() + getWidth() (see Size for more information about the width.)

Size, padding and margins

The size of a view is expressed with a width and a height. A view actually possess two pairs of width and height values.

The first pair is known as measured width and measured height. These dimensions define how big a view wants to be within its parent (see Layout for more details.) The measured dimensions can be obtained by calling getMeasuredWidth() and getMeasuredHeight().

The second pair is simply known as width and height, or sometimes drawing width and drawing height. These dimensions define the actual size of the view on screen, at drawing time and after layout. These values may, but do not have to, be different from the measured width and height. The width and height can be obtained by calling getWidth() and getHeight().

To measure its dimensions, a view takes into account its padding. The padding is expressed in pixels for the left, top, right and bottom parts of the view. Padding can be used to offset the content of the view by a specific amount of pixels. For instance, a left padding of 2 will push the view's content by 2 pixels to the right of the left edge. Padding can be set using the setPadding(int, int, int, int) or setPaddingRelative(int, int, int, int) method and queried by calling getPaddingLeft(), getPaddingTop(), getPaddingRight(), getPaddingBottom(), getPaddingStart(), getPaddingEnd().

Even though a view can define a padding, it does not provide any support for margins. However, view groups provide such a support. Refer to ViewGroup and ViewGroup.MarginLayoutParams for further information.

Layout

Layout is a two pass process: a measure pass and a layout pass. The measuring pass is implemented in measure(int, int) and is a top-down traversal of the view tree. Each view pushes dimension specifications down the tree during the recursion. At the end of the measure pass, every view has stored its measurements. The second pass happens in layout(int, int, int, int) and is also top-down. During this pass each parent is responsible for positioning all of its children using the sizes computed in the measure pass.

When a view's measure() method returns, its getMeasuredWidth() and getMeasuredHeight() values must be set, along with those for all of that view's descendants. A view's measured width and measured height values must respect the constraints imposed by the view's parents. This guarantees that at the end of the measure pass, all parents accept all of their children's measurements. A parent view may call measure() more than once on its children. For example, the parent may measure each child once with unspecified dimensions to find out how big they want to be, then call measure() on them again with actual numbers if the sum of all the children's unconstrained sizes is too big or too small.

The measure pass uses two classes to communicate dimensions. The View.MeasureSpec class is used by views to tell their parents how they want to be measured and positioned. The base LayoutParams class just describes how big the view wants to be for both width and height. For each dimension, it can specify one of:

There are subclasses of LayoutParams for different subclasses of ViewGroup. For example, AbsoluteLayout has its own subclass of LayoutParams which adds an X and Y value.

MeasureSpecs are used to push requirements down the tree from parent to child. A MeasureSpec can be in one of three modes:

To initiate a layout, call requestLayout(). This method is typically called by a view on itself when it believes that is can no longer fit within its current bounds.

Drawing

Drawing is handled by walking the tree and recording the drawing commands of any View that needs to update. After this, the drawing commands of the entire tree are issued to screen, clipped to the newly damaged area.

The tree is largely recorded and drawn in order, with parents drawn before (i.e., behind) their children, with siblings drawn in the order they appear in the tree. If you set a background drawable for a View, then the View will draw it before calling back to its onDraw() method. The child drawing order can be overridden with custom child drawing order in a ViewGroup, and with setZ(float) custom Z values} set on Views.

To force a view to draw, call invalidate().

Event Handling and Threading

The basic cycle of a view is as follows:

  1. An event comes in and is dispatched to the appropriate view. The view handles the event and notifies any listeners.
  2. If in the course of processing the event, the view's bounds may need to be changed, the view will call requestLayout().
  3. Similarly, if in the course of processing the event the view's appearance may need to be changed, the view will call invalidate().
  4. If either requestLayout() or invalidate() were called, the framework will take care of measuring, laying out, and drawing the tree as appropriate.

Note: The entire view tree is single threaded. You must always be on the UI thread when calling any method on any view. If you are doing work on other threads and want to update the state of a view from that thread, you should use a Handler.

Focus Handling

The framework will handle routine focus movement in response to user input. This includes changing the focus as views are removed or hidden, or as new views become available. Views indicate their willingness to take focus through the isFocusable() method. To change whether a view can take focus, call setFocusable(boolean). When in touch mode (see notes below) views indicate whether they still would like focus via isFocusableInTouchMode() and can change this via setFocusableInTouchMode(boolean).

Focus movement is based on an algorithm which finds the nearest neighbor in a given direction. In rare cases, the default algorithm may not match the intended behavior of the developer. In these situations, you can provide explicit overrides by using these XML attributes in the layout file:

 nextFocusDown
 nextFocusLeft
 nextFocusRight
 nextFocusUp
 

To get a particular view to take focus, call requestFocus().

Touch Mode

When a user is navigating a user interface via directional keys such as a D-pad, it is necessary to give focus to actionable items such as buttons so the user can see what will take input. If the device has touch capabilities, however, and the user begins interacting with the interface by touching it, it is no longer necessary to always highlight, or give focus to, a particular view. This motivates a mode for interaction named 'touch mode'.

For a touch capable device, once the user touches the screen, the device will enter touch mode. From this point onward, only views for which isFocusableInTouchMode() is true will be focusable, such as text editing widgets. Other views that are touchable, like buttons, will not take focus when touched; they will only fire the on click listeners.

Any time a user hits a directional key, such as a D-pad direction, the view device will exit touch mode, and find a view to take focus, so that the user may resume interacting with the user interface without touching the screen again.

The touch mode state is maintained across Activitys. Call isInTouchMode() to see whether the device is currently in touch mode.

Scrolling

The framework provides basic support for views that wish to internally scroll their content. This includes keeping track of the X and Y scroll offset as well as mechanisms for drawing scrollbars. See scrollBy(int, int), scrollTo(int, int), and awakenScrollBars() for more details.

Tags

Unlike IDs, tags are not used to identify views. Tags are essentially an extra piece of information that can be associated with a view. They are most often used as a convenience to store data related to views in the views themselves rather than by putting them in a separate structure.

Tags may be specified with character sequence values in layout XML as either a single tag using the android:tag attribute or multiple tags using the <tag> child element:

     <View ...
           android:tag="@string/mytag_value" />
     <View ...>
         <tag android:id="@+id/mytag"
              android:value="@string/mytag_value" />
     </View>
 

Tags may also be specified with arbitrary objects from code using setTag(Object) or setTag(int, Object).

Themes

By default, Views are created using the theme of the Context object supplied to their constructor; however, a different theme may be specified by using the android:theme attribute in layout XML or by passing a ContextThemeWrapper to the constructor from code.

When the android:theme attribute is used in XML, the specified theme is applied on top of the inflation context's theme (see LayoutInflater) and used for the view itself as well as any child elements.

In the following example, both views will be created using the Material dark color scheme; however, because an overlay theme is used which only defines a subset of attributes, the value of android:colorAccent defined on the inflation context's theme (e.g. the Activity theme) will be preserved.

     <LinearLayout
             ...
             android:theme="@android:theme/ThemeOverlay.Material.Dark">
         <View ...>
     </LinearLayout>
 

Properties

The View class exposes an ALPHA property, as well as several transform-related properties, such as TRANSLATION_X and TRANSLATION_Y. These properties are available both in the Property form as well as in similarly-named setter/getter methods (such as setAlpha(float) for ALPHA). These properties can be used to set persistent state associated with these rendering-related properties on the view. The properties and methods can also be used in conjunction with Animator-based animations, described more in the Animation section.

Animation

Starting with Android 3.0, the preferred way of animating views is to use the android.animation package APIs. These Animator-based classes change actual properties of the View object, such as alpha and translationX. This behavior is contrasted to that of the pre-3.0 Animation-based classes, which instead animate only how the view is drawn on the display. In particular, the ViewPropertyAnimator class makes animating these View properties particularly easy and efficient.

Alternatively, you can use the pre-3.0 animation classes to animate how Views are rendered. You can attach an Animation object to a view using setAnimation(Animation) or startAnimation(Animation). The animation can alter the scale, rotation, translation and alpha of a view over time. If the animation is attached to a view that has children, the animation will affect the entire subtree rooted by that node. When an animation is started, the framework will take care of redrawing the appropriate views until the animation completes.

Security

Sometimes it is essential that an application be able to verify that an action is being performed with the full knowledge and consent of the user, such as granting a permission request, making a purchase or clicking on an advertisement. Unfortunately, a malicious application could try to spoof the user into performing these actions, unaware, by concealing the intended purpose of the view. As a remedy, the framework offers a touch filtering mechanism that can be used to improve the security of views that provide access to sensitive functionality.

To enable touch filtering, call setFilterTouchesWhenObscured(boolean) or set the android:filterTouchesWhenObscured layout attribute to true. When enabled, the framework will discard touches that are received whenever the view's window is obscured by another visible window. As a result, the view will not receive touches whenever a toast, dialog or other window appears above the view's window.

For more fine-grained control over security, consider overriding the onFilterTouchEventForSecurity(MotionEvent) method to implement your own security policy. See also FLAG_WINDOW_IS_OBSCURED.

See also:

Summary

Nested classes

class View.AccessibilityDelegate

This class represents a delegate that can be registered in a View to enhance accessibility support via composition rather via inheritance. 

class View.BaseSavedState

Base class for derived classes that want to save and restore their own state in onSaveInstanceState()

class View.DragShadowBuilder

Creates an image that the system displays during the drag and drop operation. 

class View.MeasureSpec

A MeasureSpec encapsulates the layout requirements passed from parent to child. 

interface View.OnApplyWindowInsetsListener

Listener for applying window insets on a view in a custom way. 

interface View.OnAttachStateChangeListener

Interface definition for a callback to be invoked when this view is attached or detached from its window. 

interface View.OnClickListener

Interface definition for a callback to be invoked when a view is clicked. 

interface View.OnContextClickListener

Interface definition for a callback to be invoked when a view is context clicked. 

interface View.OnCreateContextMenuListener

Interface definition for a callback to be invoked when the context menu for this view is being built. 

interface View.OnDragListener

Interface definition for a callback to be invoked when a drag is being dispatched to this view. 

interface View.OnFocusChangeListener

Interface definition for a callback to be invoked when the focus state of a view changed. 

interface View.OnGenericMotionListener

Interface definition for a callback to be invoked when a generic motion event is dispatched to this view. 

interface View.OnHoverListener

Interface definition for a callback to be invoked when a hover event is dispatched to this view. 

interface View.OnKeyListener

Interface definition for a callback to be invoked when a hardware key event is dispatched to this view. 

interface View.OnLayoutChangeListener

Interface definition for a callback to be invoked when the layout bounds of a view changes due to layout processing. 

interface View.OnLongClickListener

Interface definition for a callback to be invoked when a view has been clicked and held. 

interface View.OnScrollChangeListener

Interface definition for a callback to be invoked when the scroll X or Y positions of a view change. 

interface View.OnSystemUiVisibilityChangeListener

Interface definition for a callback to be invoked when the status bar changes visibility. 

interface View.OnTouchListener

Interface definition for a callback to be invoked when a touch event is dispatched to this view. 

XML attributes

android:accessibilityLiveRegion Indicates to accessibility services whether the user should be notified when this view changes. 
android:accessibilityTraversalAfter Sets the id of a view after which this one is visited in accessibility traversal. 
android:accessibilityTraversalBefore Sets the id of a view before which this one is visited in accessibility traversal. 
android:alpha alpha property of the view, as a value between 0 (completely transparent) and 1 (completely opaque). 
android:background A drawable to use as the background. 
android:backgroundTint Tint to apply to the background. 
android:backgroundTintMode Blending mode used to apply the background tint. 
android:clickable Defines whether this view reacts to click events. 
android:contentDescription Defines text that briefly describes content of the view. 
android:contextClickable Defines whether this view reacts to context click events. 
android:drawingCacheQuality Defines the quality of translucent drawing caches. 
android:duplicateParentState When this attribute is set to true, the view gets its drawable state (focused, pressed, etc.) from its direct parent rather than from itself. 
android:elevation base z depth of the view

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". 

android:fadeScrollbars Defines whether to fade out scrollbars when they are not in use. 
android:fadingEdgeLength Defines the length of the fading edges. 
android:filterTouchesWhenObscured Specifies whether to filter touches when the view's window is obscured by another visible window. 
android:fitsSystemWindows Boolean internal attribute to adjust view layout based on system windows such as the status bar. 
android:focusable Boolean that controls whether a view can take focus. 
android:focusableInTouchMode Boolean that controls whether a view can take focus while in touch mode. 
android:forceHasOverlappingRendering Whether this view has elements that may overlap when drawn. 
android:foreground Defines the drawable to draw over the content. 
android:foregroundGravity Defines the gravity to apply to the foreground drawable. 
android:foregroundTint Tint to apply to the foreground. 
android:foregroundTintMode Blending mode used to apply the foreground tint. 
android:hapticFeedbackEnabled Boolean that controls whether a view should have haptic feedback enabled for events such as long presses. 
android:id Supply an identifier name for this view, to later retrieve it with View.findViewById() or Activity.findViewById()
android:importantForAccessibility Controls how this View is important for accessibility which is if it fires accessibility events and if it is reported to accessibility services that query the screen. 
android:isScrollContainer Set this if the view will serve as a scrolling container, meaning that it can be resized to shrink its overall window so that there will be space for an input method. 
android:keepScreenOn Controls whether the view's window should keep the screen on while visible. 
android:layerType Specifies the type of layer backing this view. 
android:layoutDirection Defines the direction of layout drawing. 
android:longClickable Defines whether this view reacts to long click events. 
android:minHeight Defines the minimum height of the view. 
android:minWidth Defines the minimum width of the view. 
android:nextFocusDown Defines the next view to give focus to when the next focus is FOCUS_DOWN If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed. 
android:nextFocusForward Defines the next view to give focus to when the next focus is FOCUS_FORWARD If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed. 
android:nextFocusLeft Defines the next view to give focus to when the next focus is FOCUS_LEFT
android:nextFocusRight Defines the next view to give focus to when the next focus is FOCUS_RIGHT If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed. 
android:nextFocusUp Defines the next view to give focus to when the next focus is FOCUS_UP If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed. 
android:onClick Name of the method in this View's context to invoke when the view is clicked. 
android:padding Sets the padding, in pixels, of all four edges. 
android:paddingBottom Sets the padding, in pixels, of the bottom edge; see padding
android:paddingEnd Sets the padding, in pixels, of the end edge; see padding
android:paddingLeft Sets the padding, in pixels, of the left edge; see padding
android:paddingRight Sets the padding, in pixels, of the right edge; see padding
android:paddingStart Sets the padding, in pixels, of the start edge; see padding
android:paddingTop Sets the padding, in pixels, of the top edge; see padding
android:requiresFadingEdge Defines which edges should be faded on scrolling. 
android:rotation rotation of the view, in degrees. 
android:rotationX rotation of the view around the x axis, in degrees. 
android:rotationY rotation of the view around the y axis, in degrees. 
android:saveEnabled If false, no state will be saved for this view when it is being frozen. 
android:scaleX scale of the view in the x direction. 
android:scaleY scale of the view in the y direction. 
android:scrollIndicators Defines which scroll indicators should be displayed when the view can be scrolled. 
android:scrollX The initial horizontal scroll offset, in pixels. 
android:scrollY The initial vertical scroll offset, in pixels. 
android:scrollbarAlwaysDrawHorizontalTrack Defines whether the horizontal scrollbar track should always be drawn. 
android:scrollbarAlwaysDrawVerticalTrack Defines whether the vertical scrollbar track should always be drawn. 
android:scrollbarDefaultDelayBeforeFade Defines the delay in milliseconds that a scrollbar waits before fade out. 
android:scrollbarFadeDuration Defines the delay in milliseconds that a scrollbar takes to fade out. 
android:scrollbarSize Sets the width of vertical scrollbars and height of horizontal scrollbars. 
android:scrollbarStyle Controls the scrollbar style and position. 
android:scrollbarThumbHorizontal Defines the horizontal scrollbar thumb drawable. 
android:scrollbarThumbVertical Defines the vertical scrollbar thumb drawable. 
android:scrollbarTrackHorizontal Defines the horizontal scrollbar track drawable. 
android:scrollbarTrackVertical Defines the vertical scrollbar track drawable. 
android:scrollbars Defines which scrollbars should be displayed on scrolling or not. 
android:soundEffectsEnabled Boolean that controls whether a view should have sound effects enabled for events such as clicking and touching. 
android:stateListAnimator Sets the state-based animator for the View. 
android:tag Supply a tag for this view containing a String, to be retrieved later with View.getTag() or searched for with View.findViewWithTag()
android:textAlignment Defines the alignment of the text. 
android:textDirection Defines the direction of the text. 
android:theme Specifies a theme override for a view. 
android:transformPivotX x location of the pivot point around which the view will rotate and scale. 
android:transformPivotY y location of the pivot point around which the view will rotate and scale. 
android:transitionName Names a View such that it can be identified for Transitions. 
android:translationX translation in x of the view. 
android:translationY translation in y of the view. 
android:translationZ translation in z of the view. 
android:visibility Controls the initial visibility of the view. 

Constants

int ACCESSIBILITY_LIVE_REGION_ASSERTIVE

Live region mode specifying that accessibility services should interrupt ongoing speech to immediately announce changes to this view.

int ACCESSIBILITY_LIVE_REGION_NONE

Live region mode specifying that accessibility services should not automatically announce changes to this view.

int ACCESSIBILITY_LIVE_REGION_POLITE

Live region mode specifying that accessibility services should announce changes to this view.

int DRAG_FLAG_GLOBAL

Flag indicating that a drag can cross window boundaries.

int DRAG_FLAG_GLOBAL_PERSISTABLE_URI_PERMISSION

When this flag is used with DRAG_FLAG_GLOBAL_URI_READ and/or DRAG_FLAG_GLOBAL_URI_WRITE, the URI permission grant can be persisted across device reboots until explicitly revoked with Context.revokeUriPermission.

int DRAG_FLAG_GLOBAL_PREFIX_URI_PERMISSION

When this flag is used with DRAG_FLAG_GLOBAL_URI_READ and/or DRAG_FLAG_GLOBAL_URI_WRITE, the URI permission grant applies to any URI that is a prefix match against the original granted URI.

int DRAG_FLAG_GLOBAL_URI_READ

When this flag is used with DRAG_FLAG_GLOBAL, the drag recipient will be able to request read access to the content URI(s) contained in the ClipData object.

int DRAG_FLAG_GLOBAL_URI_WRITE

When this flag is used with DRAG_FLAG_GLOBAL, the drag recipient will be able to request write access to the content URI(s) contained in the ClipData object.

int DRAG_FLAG_OPAQUE

Flag indicating that the drag shadow will be opaque.

int DRAWING_CACHE_QUALITY_AUTO

Enables automatic quality mode for the drawing cache.

int DRAWING_CACHE_QUALITY_HIGH

Enables high quality mode for the drawing cache.

int DRAWING_CACHE_QUALITY_LOW

Enables low quality mode for the drawing cache.

int FIND_VIEWS_WITH_CONTENT_DESCRIPTION

Find find views that contain the specified content description.

int FIND_VIEWS_WITH_TEXT

Find views that render the specified text.

int FOCUSABLES_ALL

View flag indicating whether addFocusables(ArrayList, int, int) should add all focusable Views regardless if they are focusable in touch mode.

int FOCUSABLES_TOUCH_MODE

View flag indicating whether addFocusables(ArrayList, int, int) should add only Views focusable in touch mode.

int FOCUS_BACKWARD

Use with focusSearch(int).

int FOCUS_DOWN

Use with focusSearch(int).

int FOCUS_FORWARD

Use with focusSearch(int).

int FOCUS_LEFT

Use with focusSearch(int).

int FOCUS_RIGHT

Use with focusSearch(int).

int FOCUS_UP

Use with focusSearch(int).

int GONE

This view is invisible, and it doesn't take any space for layout purposes.

int HAPTIC_FEEDBACK_ENABLED

View flag indicating whether this view should have haptic feedback enabled for events such as long presses.

int IMPORTANT_FOR_ACCESSIBILITY_AUTO

Automatically determine whether a view is important for accessibility.

int IMPORTANT_FOR_ACCESSIBILITY_NO

The view is not important for accessibility.

int IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS

The view is not important for accessibility, nor are any of its descendant views.

int IMPORTANT_FOR_ACCESSIBILITY_YES

The view is important for accessibility.

int INVISIBLE

This view is invisible, but it still takes up space for layout purposes.

int KEEP_SCREEN_ON

View flag indicating that the screen should remain on while the window containing this view is visible to the user.

int LAYER_TYPE_HARDWARE

Indicates that the view has a hardware layer.

int LAYER_TYPE_NONE

Indicates that the view does not have a layer.

int LAYER_TYPE_SOFTWARE

Indicates that the view has a software layer.

int LAYOUT_DIRECTION_INHERIT

Horizontal layout direction of this view is inherited from its parent.

int LAYOUT_DIRECTION_LOCALE

Horizontal layout direction of this view is from deduced from the default language script for the locale.

int LAYOUT_DIRECTION_LTR

Horizontal layout direction of this view is from Left to Right.

int LAYOUT_DIRECTION_RTL

Horizontal layout direction of this view is from Right to Left.

int MEASURED_HEIGHT_STATE_SHIFT

Bit shift of MEASURED_STATE_MASK to get to the height bits for functions that combine both width and height into a single int, such as getMeasuredState() and the childState argument of resolveSizeAndState(int, int, int).

int MEASURED_SIZE_MASK

Bits of getMeasuredWidthAndState() and getMeasuredWidthAndState() that provide the actual measured size.

int MEASURED_STATE_MASK

Bits of getMeasuredWidthAndState() and getMeasuredWidthAndState() that provide the additional state bits.

int MEASURED_STATE_TOO_SMALL

Bit of getMeasuredWidthAndState() and getMeasuredWidthAndState() that indicates the measured size is smaller that the space the view would like to have.

int NO_ID

Used to mark a View that has no ID.

int OVER_SCROLL_ALWAYS

Always allow a user to over-scroll this view, provided it is a view that can scroll.

int OVER_SCROLL_IF_CONTENT_SCROLLS

Allow a user to over-scroll this view only if the content is large enough to meaningfully scroll, provided it is a view that can scroll.

int OVER_SCROLL_NEVER

Never allow a user to over-scroll this view.

int SCREEN_STATE_OFF

Indicates that the screen has changed state and is now off.

int SCREEN_STATE_ON

Indicates that the screen has changed state and is now on.

int SCROLLBARS_INSIDE_INSET

The scrollbar style to display the scrollbars inside the padded area, increasing the padding of the view.

int SCROLLBARS_INSIDE_OVERLAY

The scrollbar style to display the scrollbars inside the content area, without increasing the padding.

int SCROLLBARS_OUTSIDE_INSET

The scrollbar style to display the scrollbars at the edge of the view, increasing the padding of the view.

int SCROLLBARS_OUTSIDE_OVERLAY

The scrollbar style to display the scrollbars at the edge of the view, without increasing the padding.

int SCROLLBAR_POSITION_DEFAULT

Position the scroll bar at the default position as determined by the system.

int SCROLLBAR_POSITION_LEFT

Position the scroll bar along the left edge.

int SCROLLBAR_POSITION_RIGHT

Position the scroll bar along the right edge.

int SCROLL_AXIS_HORIZONTAL

Indicates scrolling along the horizontal axis.

int SCROLL_AXIS_NONE

Indicates no axis of view scrolling.

int SCROLL_AXIS_VERTICAL

Indicates scrolling along the vertical axis.

int SCROLL_INDICATOR_BOTTOM

Scroll indicator direction for the bottom edge of the view.

int SCROLL_INDICATOR_END

Scroll indicator direction for the ending edge of the view.

int SCROLL_INDICATOR_LEFT

Scroll indicator direction for the left edge of the view.

int SCROLL_INDICATOR_RIGHT

Scroll indicator direction for the right edge of the view.

int SCROLL_INDICATOR_START

Scroll indicator direction for the starting edge of the view.

int SCROLL_INDICATOR_TOP

Scroll indicator direction for the top edge of the view.

int SOUND_EFFECTS_ENABLED

View flag indicating whether this view should have sound effects enabled for events such as clicking and touching.

int STATUS_BAR_HIDDEN

This constant was deprecated in API level 14. Use SYSTEM_UI_FLAG_LOW_PROFILE instead.

int STATUS_BAR_VISIBLE

This constant was deprecated in API level 14. Use SYSTEM_UI_FLAG_VISIBLE instead.

int SYSTEM_UI_FLAG_FULLSCREEN

Flag for setSystemUiVisibility(int): View has requested to go into the normal fullscreen mode so that its content can take over the screen while still allowing the user to interact with the application.

int SYSTEM_UI_FLAG_HIDE_NAVIGATION

Flag for setSystemUiVisibility(int): View has requested that the system navigation be temporarily hidden.

int SYSTEM_UI_FLAG_IMMERSIVE

Flag for setSystemUiVisibility(int): View would like to remain interactive when hiding the navigation bar with SYSTEM_UI_FLAG_HIDE_NAVIGATION.

int SYSTEM_UI_FLAG_IMMERSIVE_STICKY

Flag for setSystemUiVisibility(int): View would like to remain interactive when hiding the status bar with SYSTEM_UI_FLAG_FULLSCREEN and/or hiding the navigation bar with SYSTEM_UI_FLAG_HIDE_NAVIGATION.

int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

Flag for setSystemUiVisibility(int): View would like its window to be laid out as if it has requested SYSTEM_UI_FLAG_FULLSCREEN, even if it currently hasn't.

int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

Flag for setSystemUiVisibility(int): View would like its window to be laid out as if it has requested SYSTEM_UI_FLAG_HIDE_NAVIGATION, even if it currently hasn't.

int SYSTEM_UI_FLAG_LAYOUT_STABLE

Flag for setSystemUiVisibility(int): When using other layout flags, we would like a stable view of the content insets given to fitSystemWindows(Rect).

int SYSTEM_UI_FLAG_LIGHT_STATUS_BAR

Flag for setSystemUiVisibility(int): Requests the status bar to draw in a mode that is compatible with light status bar backgrounds.

int SYSTEM_UI_FLAG_LOW_PROFILE

Flag for setSystemUiVisibility(int): View has requested the system UI to enter an unobtrusive "low profile" mode.

int SYSTEM_UI_FLAG_VISIBLE

Special constant for setSystemUiVisibility(int): View has requested the system UI (status bar) to be visible (the default).

int SYSTEM_UI_LAYOUT_FLAGS

Flags that can impact the layout in relation to system UI.

int TEXT_ALIGNMENT_CENTER

Center the paragraph, e.g.

int TEXT_ALIGNMENT_GRAVITY

Default for the root view.

int TEXT_ALIGNMENT_INHERIT

Default text alignment.

int TEXT_ALIGNMENT_TEXT_END

Align to the end of the paragraph, e.g.

int TEXT_ALIGNMENT_TEXT_START

Align to the start of the paragraph, e.g.

int TEXT_ALIGNMENT_VIEW_END

Align to the end of the view, which is ALIGN_RIGHT if the view’s resolved layoutDirection is LTR, and ALIGN_LEFT otherwise.

int TEXT_ALIGNMENT_VIEW_START

Align to the start of the view, which is ALIGN_LEFT if the view’s resolved layoutDirection is LTR, and ALIGN_RIGHT otherwise.

int TEXT_DIRECTION_ANY_RTL

Text direction is using "any-RTL" algorithm.

int TEXT_DIRECTION_FIRST_STRONG

Text direction is using "first strong algorithm".

int TEXT_DIRECTION_FIRST_STRONG_LTR

Text direction is using "first strong algorithm".

int TEXT_DIRECTION_FIRST_STRONG_RTL

Text direction is using "first strong algorithm".

int TEXT_DIRECTION_INHERIT

Text direction is inherited through ViewGroup

int TEXT_DIRECTION_LOCALE

Text direction is coming from the system Locale.

int TEXT_DIRECTION_LTR

Text direction is forced to LTR.

int TEXT_DIRECTION_RTL

Text direction is forced to RTL.

String VIEW_LOG_TAG

The logging tag used by this class with android.util.Log.

int VISIBLE

This view is visible.

Fields

public static final Property<ViewFloat> ALPHA

A Property wrapper around the alpha functionality handled by the setAlpha(float) and getAlpha() methods.

protected static final int[] EMPTY_STATE_SET

Indicates the view has no states set.

protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET

Indicates the view is enabled, focused and selected.

protected static final int[] ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Indicates the view is enabled, focused, selected and its window has the focus.

protected static final int[] ENABLED_FOCUSED_STATE_SET

Indicates the view is enabled and has the focus.

protected static final int[] ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET

Indicates the view is enabled, focused and its window has the focus.

protected static final int[] ENABLED_SELECTED_STATE_SET

Indicates the view is enabled and selected.

protected static final int[] ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET

Indicates the view is enabled, selected and its window has the focus.

protected static final int[] ENABLED_STATE_SET

Indicates the view is enabled.

protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET

Indicates the view is enabled and that its window has focus.

protected static final int[] FOCUSED_SELECTED_STATE_SET

Indicates the view is focused and selected.

protected static final int[] FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Indicates the view is focused, selected and its window has the focus.

protected static final int[] FOCUSED_STATE_SET

Indicates the view is focused.

protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET

Indicates the view has the focus and that its window has the focus.

protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET

Indicates the view is pressed, enabled, focused and selected.

protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Indicates the view is pressed, enabled, focused, selected and its window has the focus.

protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET

Indicates the view is pressed, enabled and focused.

protected static final int[] PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET

Indicates the view is pressed, enabled, focused and its window has the focus.

protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET

Indicates the view is pressed, enabled and selected.

protected static final int[] PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET

Indicates the view is pressed, enabled, selected and its window has the focus.

protected static final int[] PRESSED_ENABLED_STATE_SET

Indicates the view is pressed and enabled.

protected static final int[] PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET

Indicates the view is pressed, enabled and its window has the focus.

protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET

Indicates the view is pressed, focused and selected.

protected static final int[] PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Indicates the view is pressed, focused, selected and its window has the focus.

protected static final int[] PRESSED_FOCUSED_STATE_SET

Indicates the view is pressed and focused.

protected static final int[] PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET

Indicates the view is pressed, focused and its window has the focus.

protected static final int[] PRESSED_SELECTED_STATE_SET

Indicates the view is pressed and selected.

protected static final int[] PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Indicates the view is pressed, selected and its window has the focus.

protected static final int[] PRESSED_STATE_SET

Indicates the view is pressed.

protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET

Indicates the view is pressed and its window has the focus.

public static final Property<ViewFloat> ROTATION

A Property wrapper around the rotation functionality handled by the setRotation(float) and getRotation() methods.

public static final Property<ViewFloat> ROTATION_X

A Property wrapper around the rotationX functionality handled by the setRotationX(float) and getRotationX() methods.

public static final Property<ViewFloat> ROTATION_Y

A Property wrapper around the rotationY functionality handled by the setRotationY(float) and getRotationY() methods.

public static final Property<ViewFloat> SCALE_X

A Property wrapper around the scaleX functionality handled by the setScaleX(float) and getScaleX() methods.

public static final Property<ViewFloat> SCALE_Y

A Property wrapper around the scaleY functionality handled by the setScaleY(float) and getScaleY() methods.

protected static final int[] SELECTED_STATE_SET

Indicates the view is selected.

protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET

Indicates the view is selected and that its window has the focus.

public static final Property<ViewFloat> TRANSLATION_X

A Property wrapper around the translationX functionality handled by the setTranslationX(float) and getTranslationX() methods.

public static final Property<ViewFloat> TRANSLATION_Y

A Property wrapper around the translationY functionality handled by the setTranslationY(float) and getTranslationY() methods.

public static final Property<ViewFloat> TRANSLATION_Z

A Property wrapper around the translationZ functionality handled by the setTranslationZ(float) and getTranslationZ() methods.

protected static final int[] WINDOW_FOCUSED_STATE_SET

Indicates the view's window has focus.

public static final Property<ViewFloat> X

A Property wrapper around the x functionality handled by the setX(float) and getX() methods.

public static final Property<ViewFloat> Y

A Property wrapper around the y functionality handled by the setY(float) and getY() methods.

public static final Property<ViewFloat> Z

A Property wrapper around the z functionality handled by the setZ(float) and getZ() methods.

Public constructors

View(Context context)

Simple constructor to use when creating a view from code.

View(Context context, AttributeSet attrs)

Constructor that is called when inflating a view from XML.

View(Context context, AttributeSet attrs, int defStyleAttr)

Perform inflation from XML and apply a class-specific base style from a theme attribute.

View(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Perform inflation from XML and apply a class-specific base style from a theme attribute or style resource.

Public methods

void addChildrenForAccessibility(ArrayList<View> outChildren)

Adds the children of this View relevant for accessibility to the given list as output.

void addFocusables(ArrayList<View> views, int direction)

Add any focusable views that are descendants of this view (possibly including this view if it is focusable itself) to views.

void addFocusables(ArrayList<View> views, int direction, int focusableMode)

Adds any focusable views that are descendants of this view (possibly including this view if it is focusable itself) to views.

void addOnAttachStateChangeListener(View.OnAttachStateChangeListener listener)

Add a listener for attach state changes.

void addOnLayoutChangeListener(View.OnLayoutChangeListener listener)

Add a listener that will be called when the bounds of the view change due to layout processing.

void addTouchables(ArrayList<View> views)

Add any touchable views that are descendants of this view (possibly including this view if it is touchable itself) to views.

ViewPropertyAnimator animate()

This method returns a ViewPropertyAnimator object, which can be used to animate specific properties on this View.

void announceForAccessibility(CharSequence text)

Convenience method for sending a TYPE_ANNOUNCEMENT AccessibilityEvent to make an announcement which is related to some sort of a context change for which none of the events representing UI transitions is a good fit.

void bringToFront()

Change the view's z order in the tree, so it's on top of other sibling views.

void buildDrawingCache(boolean autoScale)

Forces the drawing cache to be built if the drawing cache is invalid.

void buildDrawingCache()

Calling this method is equivalent to calling buildDrawingCache(false).

void buildLayer()

Forces this view's layer to be created and this view to be rendered into its layer.

boolean callOnClick()

Directly call any attached OnClickListener.

boolean canResolveLayoutDirection()

Check if layout direction resolution can be done.

boolean canResolveTextAlignment()

Check if text alignment resolution can be done.

boolean canResolveTextDirection()

Check if text direction resolution can be done.

boolean canScrollHorizontally(int direction)

Check if this view can be scrolled horizontally in a certain direction.

boolean canScrollVertically(int direction)

Check if this view can be scrolled vertically in a certain direction.

final void cancelDragAndDrop()

Cancels an ongoing drag and drop operation.

void cancelLongPress()

Cancels a pending long press.

final void cancelPendingInputEvents()

Cancel any deferred high-level input events that were previously posted to the event queue.

boolean checkInputConnectionProxy(View view)

Called by the InputMethodManager when a view who is not the current input connection target is trying to make a call on the manager.

void clearAnimation()

Cancels any animations for this view.

void clearFocus()

Called when this view wants to give up focus.

static int combineMeasuredStates(int curState, int newState)

Merge two states as returned by getMeasuredState().

void computeScroll()

Called by a parent to request that a child update its values for mScrollX and mScrollY if necessary.

WindowInsets computeSystemWindowInsets(WindowInsets in, Rect outLocalInsets)

Compute insets that should be consumed by this view and the ones that should propagate to those under it.

AccessibilityNodeInfo createAccessibilityNodeInfo()

Returns an AccessibilityNodeInfo representing this view from the point of view of an AccessibilityService.

void createContextMenu(ContextMenu menu)

Show the context menu for this view.

void destroyDrawingCache()

Frees the resources used by the drawing cache.

WindowInsets dispatchApplyWindowInsets(WindowInsets insets)

Request to apply the given window insets to this view or another view in its subtree.

void dispatchConfigurationChanged(Configuration newConfig)

Dispatch a notification about a resource configuration change down the view hierarchy.

void dispatchDisplayHint(int hint)

Dispatch a hint about whether this view is displayed.

boolean dispatchDragEvent(DragEvent event)

Detects if this View is enabled and has a drag event listener.

void dispatchDrawableHotspotChanged(float x, float y)

Dispatches drawableHotspotChanged to all of this View's children.

void dispatchFinishTemporaryDetach()

Dispatch onFinishTemporaryDetach() to this View and its direct children if this is a container View.

boolean dispatchGenericMotionEvent(MotionEvent event)

Dispatch a generic motion event.

boolean dispatchKeyEvent(KeyEvent event)

Dispatch a key event to the next view on the focus path.

boolean dispatchKeyEventPreIme(KeyEvent event)

Dispatch a key event before it is processed by any input method associated with the view hierarchy.

boolean dispatchKeyShortcutEvent(KeyEvent event)

Dispatches a key shortcut event.

boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed)

Dispatch a fling to a nested scrolling parent.

boolean dispatchNestedPreFling(float velocityX, float velocityY)

Dispatch a fling to a nested scrolling parent before it is processed by this view.

boolean dispatchNestedPrePerformAccessibilityAction(int action, Bundle arguments)

Report an accessibility action to this view's parents for delegated processing.

boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow)

Dispatch one step of a nested scroll in progress before this view consumes any portion of it.

boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow)

Dispatch one step of a nested scroll in progress.

boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event)

Dispatches an AccessibilityEvent to the View first and then to its children for adding their text content to the event.

void dispatchProvideStructure(ViewStructure structure)

Dispatch creation of ViewStructure down the hierarchy.

void dispatchStartTemporaryDetach()

Dispatch onStartTemporaryDetach() to this View and its direct children if this is a container View.

void dispatchSystemUiVisibilityChanged(int visibility)

Dispatch callbacks to setOnSystemUiVisibilityChangeListener(View.OnSystemUiVisibilityChangeListener) down the view hierarchy.

boolean dispatchTouchEvent(MotionEvent event)

Pass the touch screen motion event down to the target view, or this view if it is the target.

boolean dispatchTrackballEvent(MotionEvent event)

Pass a trackball motion event down to the focused view.

boolean dispatchUnhandledMove(View focused, int direction)

This method is the last chance for the focused view and its ancestors to respond to an arrow key.

void dispatchWindowFocusChanged(boolean hasFocus)

Called when the window containing this view gains or loses window focus.

void dispatchWindowSystemUiVisiblityChanged(int visible)

Dispatch callbacks to onWindowSystemUiVisibilityChanged(int) down the view hierarchy.

void dispatchWindowVisibilityChanged(int visibility)

Dispatch a window visibility change down the view hierarchy.

void draw(Canvas canvas)

Manually render this view (and all of its children) to the given Canvas.

void drawableHotspotChanged(float x, float y)

This function is called whenever the view hotspot changes and needs to be propagated to drawables or child views managed by the view.

View findFocus()

Find the view in the hierarchy rooted at this view that currently has focus.

final View findViewById(int id)

Look for a child view with the given id.

final View findViewWithTag(Object tag)

Look for a child view with the given tag.

void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags)

Finds the Views that contain given text.

View focusSearch(int direction)

Find the nearest view in the specified direction that can take focus.

void forceHasOverlappingRendering(boolean hasOverlappingRendering)

Sets the behavior for overlapping rendering for this view (see hasOverlappingRendering() for more details on this behavior).

void forceLayout()

Forces this view to be laid out during the next layout pass.

static int generateViewId()

Generate a value suitable for use in setId(int).

CharSequence getAccessibilityClassName()

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

int getAccessibilityLiveRegion()

Gets the live region mode for this View.

AccessibilityNodeProvider getAccessibilityNodeProvider()

Gets the provider for managing a virtual view hierarchy rooted at this View and reported to AccessibilityServices that explore the window content.

int getAccessibilityTraversalAfter()

Gets the id of a view after which this one is visited in accessibility traversal.

int getAccessibilityTraversalBefore()

Gets the id of a view before which this one is visited in accessibility traversal.

float getAlpha()

The opacity of the view.

Animation getAnimation()

Get the animation currently associated with this view.

IBinder getApplicationWindowToken()

Retrieve a unique token identifying the top-level "real" window of the window that this view is attached to.

Drawable getBackground()

Gets the background drawable

ColorStateList getBackgroundTintList()

Return the tint applied to the background drawable, if specified.

PorterDuff.Mode getBackgroundTintMode()

Return the blending mode used to apply the tint to the background drawable, if specified.

int getBaseline()

Return the offset of the widget's text baseline from the widget's top boundary.

final int getBottom()

Bottom position of this view relative to its parent.

float getCameraDistance()

Gets the distance along the Z axis from the camera to this view.

boolean getClipBounds(Rect outRect)

Populates an output rectangle with the clip bounds of the view, returning true if successful or false if the view's clip bounds are null.

Rect getClipBounds()

Returns a copy of the current clipBounds.

final boolean getClipToOutline()

Returns whether the Outline should be used to clip the contents of the View.

CharSequence getContentDescription()

Returns the View's content description.

final Context getContext()

Returns the context the view is running in, through which it can access the current theme, resources, etc.

static int getDefaultSize(int size, int measureSpec)

Utility to return a default size.

Display getDisplay()

Gets the logical display to which the view's window has been attached.

final int[] getDrawableState()

Return an array of resource IDs of the drawable states representing the current state of the view.

Bitmap getDrawingCache()

Calling this method is equivalent to calling getDrawingCache(false).

Bitmap getDrawingCache(boolean autoScale)

Returns the bitmap in which this view drawing is cached.

int getDrawingCacheBackgroundColor()
int getDrawingCacheQuality()

Returns the quality of the drawing cache.

void getDrawingRect(Rect outRect)

Return the visible drawing bounds of your view.

long getDrawingTime()

Return the time at which the drawing of the view hierarchy started.

float getElevation()

The base elevation of this view relative to its parent, in pixels.

boolean getFilterTouchesWhenObscured()

Gets whether the framework should discard touches when the view's window is obscured by another visible window.

boolean getFitsSystemWindows()

Check for state of setFitsSystemWindows(boolean).

ArrayList<View> getFocusables(int direction)

Find and return all focusable views that are descendants of this view, possibly including this view if it is focusable itself.

void getFocusedRect(Rect r)

When a view has focus and the user navigates away from it, the next view is searched for starting from the rectangle filled in by this method.

Drawable getForeground()

Returns the drawable used as the foreground of this View.

int getForegroundGravity()

Describes how the foreground is positioned.

ColorStateList getForegroundTintList()

Return the tint applied to the foreground drawable, if specified.

PorterDuff.Mode getForegroundTintMode()

Return the blending mode used to apply the tint to the foreground drawable, if specified.

final boolean getGlobalVisibleRect(Rect r)
boolean getGlobalVisibleRect(Rect r, Point globalOffset)

If some part of this view is not clipped by any of its parents, then return that area in r in global (root) coordinates.

Handler getHandler()
final boolean getHasOverlappingRendering()

Returns the value for overlapping rendering that is used internally.

final int getHeight()

Return the height of your view.

void getHitRect(Rect outRect)

Hit rectangle in parent's coordinates

int getHorizontalFadingEdgeLength()

Returns the size of the horizontal faded edges used to indicate that more content in this view is visible.

int getId()

Returns this view's identifier.

int getImportantForAccessibility()

Gets the mode for determining whether this View is important for accessibility which is if it fires accessibility events and if it is reported to accessibility services that query the screen.

boolean getKeepScreenOn()

Returns whether the screen should remain on, corresponding to the current value of KEEP_SCREEN_ON.

KeyEvent.DispatcherState getKeyDispatcherState()

Return the global KeyEvent.DispatcherState for this view's window.

int getLabelFor()

Gets the id of a view for which this view serves as a label for accessibility purposes.

int getLayerType()

Indicates what type of layer is currently associated with this view.

int getLayoutDirection()

Returns the resolved layout direction for this view.

ViewGroup.LayoutParams getLayoutParams()

Get the LayoutParams associated with this view.

final int getLeft()

Left position of this view relative to its parent.

final boolean getLocalVisibleRect(Rect r)
void getLocationInWindow(int[] outLocation)

Computes the coordinates of this view in its window.

void getLocationOnScreen(int[] outLocation)

Computes the coordinates of this view on the screen.

Matrix getMatrix()

The transform matrix of this view, which is calculated based on the current rotation, scale, and pivot properties.

final int getMeasuredHeight()

Like getMeasuredHeightAndState(), but only returns the raw width component (that is the result is masked by MEASURED_SIZE_MASK).

final int getMeasuredHeightAndState()

Return the full height measurement information for this view as computed by the most recent call to measure(int, int).

final int getMeasuredState()

Return only the state bits of getMeasuredWidthAndState() and getMeasuredHeightAndState(), combined into one integer.

final int getMeasuredWidth()

Like getMeasuredWidthAndState(), but only returns the raw width component (that is the result is masked by MEASURED_SIZE_MASK).

final int getMeasuredWidthAndState()

Return the full width measurement information for this view as computed by the most recent call to measure(int, int).

int getMinimumHeight()

Returns the minimum height of the view.

int getMinimumWidth()

Returns the minimum width of the view.

int getNextFocusDownId()

Gets the id of the view to use when the next focus is FOCUS_DOWN.

int getNextFocusForwardId()

Gets the id of the view to use when the next focus is FOCUS_FORWARD.

int getNextFocusLeftId()

Gets the id of the view to use when the next focus is FOCUS_LEFT.

int getNextFocusRightId()

Gets the id of the view to use when the next focus is FOCUS_RIGHT.

int getNextFocusUpId()

Gets the id of the view to use when the next focus is FOCUS_UP.

View.OnFocusChangeListener getOnFocusChangeListener()

Returns the focus-change callback registered for this view.

ViewOutlineProvider getOutlineProvider()

Returns the current ViewOutlineProvider of the view, which generates the Outline that defines the shape of the shadow it casts, and enables outline clipping.

int getOverScrollMode()

Returns the over-scroll mode for this view.

ViewOverlay getOverlay()

Returns the overlay for this view, creating it if it does not yet exist.

int getPaddingBottom()

Returns the bottom padding of this view.

int getPaddingEnd()

Returns the end padding of this view depending on its resolved layout direction.

int getPaddingLeft()

Returns the left padding of this view.

int getPaddingRight()

Returns the right padding of this view.

int getPaddingStart()

Returns the start padding of this view depending on its resolved layout direction.

int getPaddingTop()

Returns the top padding of this view.

final ViewParent getParent()

Gets the parent of this view.

ViewParent getParentForAccessibility()

Gets the parent for accessibility purposes.

float getPivotX()

The x location of the point around which the view is rotated and scaled.

float getPivotY()

The y location of the point around which the view is rotated and scaled.

PointerIcon getPointerIcon()

Gets the pointer icon for the current view.

Resources getResources()

Returns the resources associated with this view.

final int getRight()

Right position of this view relative to its parent.

View getRootView()

Finds the topmost view in the current view hierarchy.

WindowInsets getRootWindowInsets()

Provide original WindowInsets that are dispatched to the view hierarchy.

float getRotation()

The degrees that the view is rotated around the pivot point.

float getRotationX()

The degrees that the view is rotated around the horizontal axis through the pivot point.

float getRotationY()

The degrees that the view is rotated around the vertical axis through the pivot point.

float getScaleX()

The amount that the view is scaled in x around the pivot point, as a proportion of the view's unscaled width.

float getScaleY()

The amount that the view is scaled in y around the pivot point, as a proportion of the view's unscaled height.

int getScrollBarDefaultDelayBeforeFade()

Returns the delay before scrollbars fade.

int getScrollBarFadeDuration()

Returns the scrollbar fade duration.

int getScrollBarSize()

Returns the scrollbar size.

int getScrollBarStyle()

Returns the current scrollbar style.

int getScrollIndicators()

Returns a bitmask representing the enabled scroll indicators.

final int getScrollX()

Return the scrolled left position of this view.

final int getScrollY()

Return the scrolled top position of this view.

int getSolidColor()

Override this if your view is known to always be drawn on top of a solid color background, and needs to draw fading edges.

StateListAnimator getStateListAnimator()

Returns the current StateListAnimator if exists.

int getSystemUiVisibility()

Returns the last setSystemUiVisibility(int) that this view has requested.

Object getTag()

Returns this view's tag.

Object getTag(int key)

Returns the tag associated with this view and the specified key.

int getTextAlignment()

Return the resolved text alignment.

int getTextDirection()

Return the resolved text direction.

final int getTop()

Top position of this view relative to its parent.

TouchDelegate getTouchDelegate()

Gets the TouchDelegate for this View.

ArrayList<View> getTouchables()

Find and return all touchable views that are descendants of this view, possibly including this view if it is touchable itself.

String getTransitionName()

Returns the name of the View to be used to identify Views in Transitions.

float getTranslationX()

The horizontal location of this view relative to its left position.

float getTranslationY()

The vertical location of this view relative to its top position.

float getTranslationZ()

The depth location of this view relative to its elevation.

int getVerticalFadingEdgeLength()

Returns the size of the vertical faded edges used to indicate that more content in this view is visible.

int getVerticalScrollbarPosition()
int getVerticalScrollbarWidth()

Returns the width of the vertical scrollbar.

ViewTreeObserver getViewTreeObserver()

Returns the ViewTreeObserver for this view's hierarchy.

int getVisibility()

Returns the visibility status for this view.

final int getWidth()

Return the width of the your view.

WindowId getWindowId()

Retrieve the WindowId for the window this view is currently attached to.

int getWindowSystemUiVisibility()

Returns the current system UI visibility that is currently set for the entire window.

IBinder getWindowToken()

Retrieve a unique token identifying the window this view is attached to.

int getWindowVisibility()

Returns the current visibility of the window this view is attached to (either GONE, INVISIBLE, or VISIBLE).

void getWindowVisibleDisplayFrame(Rect outRect)

Retrieve the overall visible display size in which the window this view is attached to has been positioned in.

float getX()

The visual x position of this view, in pixels.

float getY()

The visual y position of this view, in pixels.

float getZ()

The visual z position of this view, in pixels.

boolean hasFocus()

Returns true if this view has focus itself, or is the ancestor of the view that has focus.

boolean hasFocusable()

Returns true if this view is focusable or if it contains a reachable View for which hasFocusable() returns true.

boolean hasNestedScrollingParent()

Returns true if this view has a nested scrolling parent.

boolean hasOnClickListeners()

Return whether this view has an attached OnClickListener.

boolean hasOverlappingRendering()

Returns whether this View has content which overlaps.

boolean hasTransientState()

Indicates whether the view is currently tracking transient state that the app should not need to concern itself with saving and restoring, but that the framework should take special note to preserve when possible.

boolean hasWindowFocus()

Returns true if this view is in a window that currently has window focus.

static View inflate(Context context, int resource, ViewGroup root)

Inflate a view from an XML resource.

void invalidate()

Invalidate the whole view.

void invalidate(Rect dirty)

Mark the area defined by dirty as needing to be drawn.

void invalidate(int l, int t, int r, int b)

Mark the area defined by the rect (l,t,r,b) as needing to be drawn.

void invalidateDrawable(Drawable drawable)

Invalidates the specified Drawable.

void invalidateOutline()

Called to rebuild this View's Outline from its outline provider

boolean isAccessibilityFocused()

Returns whether this View is accessibility focused.

boolean isActivated()

Indicates the activation state of this view.

boolean isAttachedToWindow()

Returns true if this view is currently attached to a window.

boolean isClickable()

Indicates whether this view reacts to click events or not.

boolean isContextClickable()

Indicates whether this view reacts to context clicks or not.

boolean isDirty()

True if this view has changed since the last time being drawn.

boolean isDrawingCacheEnabled()

Indicates whether the drawing cache is enabled for this view.

boolean isDuplicateParentStateEnabled()

Indicates whether this duplicates its drawable state from its parent.

boolean isEnabled()

Returns the enabled status for this view.

final boolean isFocusable()

Returns whether this View is able to take focus.

final boolean isFocusableInTouchMode()

When a view is focusable, it may not want to take focus when in touch mode.

boolean isFocused()

Returns true if this view has focus

boolean isHapticFeedbackEnabled()
boolean isHardwareAccelerated()

Indicates whether this view is attached to a hardware accelerated window or not.

boolean isHorizontalFadingEdgeEnabled()

Indicate whether the horizontal edges are faded when the view is scrolled horizontally.

boolean isHorizontalScrollBarEnabled()

Indicate whether the horizontal scrollbar should be drawn or not.

boolean isHovered()

Returns true if the view is currently hovered.

boolean isImportantForAccessibility()

Computes whether this view should be exposed for accessibility.

boolean isInEditMode()

Indicates whether this View is currently in edit mode.

boolean isInLayout()

Returns whether the view hierarchy is currently undergoing a layout pass.

boolean isInTouchMode()

Returns whether the device is currently in touch mode.

boolean isLaidOut()

Returns true if this view has been through at least one layout since it was last attached to or detached from a window.

boolean isLayoutDirectionResolved()
boolean isLayoutRequested()

Indicates whether or not this view's layout will be requested during the next hierarchy layout pass.

boolean isLongClickable()

Indicates whether this view reacts to long click events or not.

boolean isNestedScrollingEnabled()

Returns true if nested scrolling is enabled for this view.

boolean isOpaque()

Indicates whether this View is opaque.

boolean isPaddingRelative()

Return if the padding has been set through relative values setPaddingRelative(int, int, int, int) or through

boolean isPressed()

Indicates whether the view is currently in pressed state.

boolean isSaveEnabled()

Indicates whether this view will save its state (that is, whether its onSaveInstanceState() method will be called).

boolean isSaveFromParentEnabled()

Indicates whether the entire hierarchy under this view will save its state when a state saving traversal occurs from its parent.

boolean isScrollContainer()

Indicates whether this view is one of the set of scrollable containers in its window.

boolean isScrollbarFadingEnabled()

Returns true if scrollbars will fade when this view is not scrolling

boolean isSelected()

Indicates the selection state of this view.

boolean isShown()

Returns the visibility of this view and all of its ancestors

boolean isSoundEffectsEnabled()
final boolean isTemporarilyDetached()
boolean isTextAlignmentResolved()
boolean isTextDirectionResolved()
boolean isVerticalFadingEdgeEnabled()

Indicate whether the vertical edges are faded when the view is scrolled horizontally.

boolean isVerticalScrollBarEnabled()

Indicate whether the vertical scrollbar should be drawn or not.

void jumpDrawablesToCurrentState()

Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.

void layout(int l, int t, int r, int b)

Assign a size and position to a view and all of its descendants

This is the second phase of the layout mechanism.

final void measure(int widthMeasureSpec, int heightMeasureSpec)

This is called to find out how big a view should be.

void offsetLeftAndRight(int offset)

Offset this view's horizontal location by the specified amount of pixels.

void offsetTopAndBottom(int offset)

Offset this view's vertical location by the specified number of pixels.

WindowInsets onApplyWindowInsets(WindowInsets insets)

Called when the view should apply WindowInsets according to its internal policy.

void onCancelPendingInputEvents()

Called as the result of a call to cancelPendingInputEvents() on this view or a parent view.

boolean onCheckIsTextEditor()

Check whether the called view is a text editor, in which case it would make sense to automatically display a soft input window for it.

InputConnection onCreateInputConnection(EditorInfo outAttrs)

Create a new InputConnection for an InputMethod to interact with the view.

boolean onDragEvent(DragEvent event)

Handles drag events sent by the system following a call to startDragAndDrop().

void onDrawForeground(Canvas canvas)

Draw any foreground content for this view.

boolean onFilterTouchEventForSecurity(MotionEvent event)

Filter the touch event to apply security policies.

void onFinishTemporaryDetach()

Called after onStartTemporaryDetach() when the container is done changing the view.

boolean onGenericMotionEvent(MotionEvent event)

Implement this method to handle generic motion events.

void onHoverChanged(boolean hovered)

Implement this method to handle hover state changes.

boolean onHoverEvent(MotionEvent event)

Implement this method to handle hover events.

void onInitializeAccessibilityEvent(AccessibilityEvent event)

Initializes an AccessibilityEvent with information about this View which is the event source.

void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)

Initializes an AccessibilityNodeInfo with information about this view.

boolean onKeyDown(int keyCode, KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyDown(): perform press of the view when KEYCODE_DPAD_CENTER or KEYCODE_ENTER is released, if the view is enabled and clickable.

boolean onKeyLongPress(int keyCode, KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyLongPress(): always returns false (doesn't handle the event).

boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyMultiple(): always returns false (doesn't handle the event).

boolean onKeyPreIme(int keyCode, KeyEvent event)

Handle a key event before it is processed by any input method associated with the view hierarchy.

boolean onKeyShortcut(int keyCode, KeyEvent event)

Called on the focused view when a key shortcut event is not handled.

boolean onKeyUp(int keyCode, KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyUp(): perform clicking of the view when KEYCODE_DPAD_CENTER, KEYCODE_ENTER or KEYCODE_SPACE is released.

void onPopulateAccessibilityEvent(AccessibilityEvent event)

Called from dispatchPopulateAccessibilityEvent(AccessibilityEvent) giving a chance to this View to populate the accessibility event with its text content.

void onProvideStructure(ViewStructure structure)

Called when assist structure is being retrieved from a view as part of Activity.onProvideAssistData.

void onProvideVirtualStructure(ViewStructure structure)

Called when assist structure is being retrieved from a view as part of Activity.onProvideAssistData to generate additional virtual structure under this view.

PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex)

Returns the pointer icon for the motion event, or null if it doesn't specify the icon.

void onRtlPropertiesChanged(int layoutDirection)

Called when any RTL property (layout direction or text direction or text alignment) has been changed.

void onScreenStateChanged(int screenState)

This method is called whenever the state of the screen this view is attached to changes.

void onStartTemporaryDetach()

This is called when a container is going to temporarily detach a child, with ViewGroup.detachViewFromParent.

boolean onTouchEvent(MotionEvent event)

Implement this method to handle touch screen motion events.

boolean onTrackballEvent(MotionEvent event)

Implement this method to handle trackball motion events.

void onVisibilityAggregated(boolean isVisible)

Called when the user-visibility of this View is potentially affected by a change to this view itself, an ancestor view or the window this view is attached to.

void onWindowFocusChanged(boolean hasWindowFocus)

Called when the window containing this view gains or loses focus.

void onWindowSystemUiVisibilityChanged(int visible)

Override to find out when the window's requested system UI visibility has changed, that is the value returned by getWindowSystemUiVisibility().

boolean performAccessibilityAction(int action, Bundle arguments)

Performs the specified accessibility action on the view.

boolean performClick()

Call this view's OnClickListener, if it is defined.

boolean performContextClick(float x, float y)

Call this view's OnContextClickListener, if it is defined.

boolean performContextClick()

Call this view's OnContextClickListener, if it is defined.

boolean performHapticFeedback(int feedbackConstant)

BZZZTT!!1!

Provide haptic feedback to the user for this view.

boolean performHapticFeedback(int feedbackConstant, int flags)

BZZZTT!!1!

Like performHapticFeedback(int), with additional options.

boolean performLongClick(float x, float y)

Calls this view's OnLongClickListener, if it is defined.

boolean performLongClick()

Calls this view's OnLongClickListener, if it is defined.

void playSoundEffect(int soundConstant)

Play a sound effect for this view.

boolean post(Runnable action)

Causes the Runnable to be added to the message queue.

boolean postDelayed(Runnable action, long delayMillis)

Causes the Runnable to be added to the message queue, to be run after the specified amount of time elapses.

void postInvalidate()

Cause an invalidate to happen on a subsequent cycle through the event loop.

void postInvalidate(int left, int top, int right, int bottom)

Cause an invalidate of the specified area to happen on a subsequent cycle through the event loop.

void postInvalidateDelayed(long delayMilliseconds, int left, int top, int right, int bottom)

Cause an invalidate of the specified area to happen on a subsequent cycle through the event loop.

void postInvalidateDelayed(long delayMilliseconds)

Cause an invalidate to happen on a subsequent cycle through the event loop.

void postInvalidateOnAnimation(int left, int top, int right, int bottom)

Cause an invalidate of the specified area to happen on the next animation time step, typically the next display frame.

void postInvalidateOnAnimation()

Cause an invalidate to happen on the next animation time step, typically the next display frame.

void postOnAnimation(Runnable action)

Causes the Runnable to execute on the next animation time step.

void postOnAnimationDelayed(Runnable action, long delayMillis)

Causes the Runnable to execute on the next animation time step, after the specified amount of time elapses.

void refreshDrawableState()

Call this to force a view to update its drawable state.

boolean removeCallbacks(Runnable action)

Removes the specified Runnable from the message queue.

void removeOnAttachStateChangeListener(View.OnAttachStateChangeListener listener)

Remove a listener for attach state changes.

void removeOnLayoutChangeListener(View.OnLayoutChangeListener listener)

Remove a listener for layout changes.

void requestApplyInsets()

Ask that a new dispatch of onApplyWindowInsets(WindowInsets) be performed.

void requestFitSystemWindows()

This method was deprecated in API level 20. Use requestApplyInsets() for newer platform versions.

final boolean requestFocus(int direction)

Call this to try to give focus to a specific view or to one of its descendants and give it a hint about what direction focus is heading.

final boolean requestFocus()

Call this to try to give focus to a specific view or to one of its descendants.

boolean requestFocus(int direction, Rect previouslyFocusedRect)

Call this to try to give focus to a specific view or to one of its descendants and give it hints about the direction and a specific rectangle that the focus is coming from.

final boolean requestFocusFromTouch()

Call this to try to give focus to a specific view or to one of its descendants.

void requestLayout()

Call this when something has changed which has invalidated the layout of this view.

boolean requestRectangleOnScreen(Rect rectangle)

Request that a rectangle of this view be visible on the screen, scrolling if necessary just enough.

boolean requestRectangleOnScreen(Rect rectangle, boolean immediate)

Request that a rectangle of this view be visible on the screen, scrolling if necessary just enough.

final void requestUnbufferedDispatch(MotionEvent event)

Request unbuffered dispatch of the given stream of MotionEvents to this View.

static int resolveSize(int size, int measureSpec)

Version of resolveSizeAndState(int, int, int) returning only the MEASURED_SIZE_MASK bits of the result.

static int resolveSizeAndState(int size, int measureSpec, int childMeasuredState)

Utility to reconcile a desired size and state, with constraints imposed by a MeasureSpec.

void restoreHierarchyState(SparseArray<Parcelable> container)

Restore this view hierarchy's frozen state from the given container.

void saveHierarchyState(SparseArray<Parcelable> container)

Store this view hierarchy's frozen state into the given container.

void scheduleDrawable(Drawable who, Runnable what, long when)

Schedules an action on a drawable to occur at a specified time.

void scrollBy(int x, int y)

Move the scrolled position of your view.

void scrollTo(int x, int y)

Set the scrolled position of your view.

void sendAccessibilityEvent(int eventType)

Sends an accessibility event of the given type.

void sendAccessibilityEventUnchecked(AccessibilityEvent event)

This method behaves exactly as sendAccessibilityEvent(int) but takes as an argument an empty AccessibilityEvent and does not perform a check whether accessibility is enabled.

void setAccessibilityDelegate(View.AccessibilityDelegate delegate)

Sets a delegate for implementing accessibility support via composition (as opposed to inheritance).

void setAccessibilityLiveRegion(int mode)

Sets the live region mode for this view.

void setAccessibilityTraversalAfter(int afterId)

Sets the id of a view after which this one is visited in accessibility traversal.

void setAccessibilityTraversalBefore(int beforeId)

Sets the id of a view before which this one is visited in accessibility traversal.

void setActivated(boolean activated)

Changes the activated state of this view.

void setAlpha(float alpha)

Sets the opacity of the view to a value from 0 to 1, where 0 means the view is completely transparent and 1 means the view is completely opaque.

void setAnimation(Animation animation)

Sets the next animation to play for this view.

void setBackground(Drawable background)

Set the background to a given Drawable, or remove the background.

void setBackgroundColor(int color)

Sets the background color for this view.

void setBackgroundDrawable(Drawable background)

This method was deprecated in API level 16. use setBackground(Drawable) instead

void setBackgroundResource(int resid)

Set the background to a given resource.

void setBackgroundTintList(ColorStateList tint)

Applies a tint to the background drawable.

void setBackgroundTintMode(PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setBackgroundTintList(ColorStateList)} to the background drawable.

final void setBottom(int bottom)

Sets the bottom position of this view relative to its parent.

void setCameraDistance(float distance)

Sets the distance along the Z axis (orthogonal to the X/Y plane on which views are drawn) from the camera to this view.

void setClickable(boolean clickable)

Enables or disables click events for this view.

void setClipBounds(Rect clipBounds)

Sets a rectangular area on this view to which the view will be clipped when it is drawn.

void setClipToOutline(boolean clipToOutline)

Sets whether the View's Outline should be used to clip the contents of the View.

void setContentDescription(CharSequence contentDescription)

Sets the View's content description.

void setContextClickable(boolean contextClickable)

Enables or disables context clicking for this view.

void setDrawingCacheBackgroundColor(int color)

Setting a solid background color for the drawing cache's bitmaps will improve performance and memory usage.

void setDrawingCacheEnabled(boolean enabled)

Enables or disables the drawing cache.

void setDrawingCacheQuality(int quality)

Set the drawing cache quality of this view.

void setDuplicateParentStateEnabled(boolean enabled)

Enables or disables the duplication of the parent's state into this view.

void setElevation(float elevation)

Sets the base elevation of this view, in pixels.

void setEnabled(boolean enabled)

Set the enabled state of this view.

void setFadingEdgeLength(int length)

Set the size of the faded edge used to indicate that more content in this view is available.

void setFilterTouchesWhenObscured(boolean enabled)

Sets whether the framework should discard touches when the view's window is obscured by another visible window.

void setFitsSystemWindows(boolean fitSystemWindows)

Sets whether or not this view should account for system screen decorations such as the status bar and inset its content; that is, controlling whether the default implementation of fitSystemWindows(Rect) will be executed.

void setFocusable(boolean focusable)

Set whether this view can receive the focus.

void setFocusableInTouchMode(boolean focusableInTouchMode)

Set whether this view can receive focus while in touch mode.

void setForeground(Drawable foreground)

Supply a Drawable that is to be rendered on top of all of the content in the view.

void setForegroundGravity(int gravity)

Describes how the foreground is positioned.

void setForegroundTintList(ColorStateList tint)

Applies a tint to the foreground drawable.

void setForegroundTintMode(PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setForegroundTintList(ColorStateList)} to the background drawable.

void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled)

Set whether this view should have haptic feedback for events such as long presses.

void setHasTransientState(boolean hasTransientState)

Set whether this view is currently tracking transient state that the framework should attempt to preserve when possible.

void setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled)

Define whether the horizontal edges should be faded when this view is scrolled horizontally.

void setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled)

Define whether the horizontal scrollbar should be drawn or not.

void setHovered(boolean hovered)

Sets whether the view is currently hovered.

void setId(int id)

Sets the identifier for this view.

void setImportantForAccessibility(int mode)

Sets how to determine whether this view is important for accessibility which is if it fires accessibility events and if it is reported to accessibility services that query the screen.

void setKeepScreenOn(boolean keepScreenOn)

Controls whether the screen should remain on, modifying the value of KEEP_SCREEN_ON.

void setLabelFor(int id)

Sets the id of a view for which this view serves as a label for accessibility purposes.

void setLayerPaint(Paint paint)

Updates the Paint object used with the current layer (used only if the current layer type is not set to LAYER_TYPE_NONE).

void setLayerType(int layerType, Paint paint)

Specifies the type of layer backing this view.

void setLayoutDirection(int layoutDirection)

Set the layout direction for this view.

void setLayoutParams(ViewGroup.LayoutParams params)

Set the layout parameters associated with this view.

final void setLeft(int left)

Sets the left position of this view relative to its parent.

void setLongClickable(boolean longClickable)

Enables or disables long click events for this view.

void setMinimumHeight(int minHeight)

Sets the minimum height of the view.

void setMinimumWidth(int minWidth)

Sets the minimum width of the view.

void setNestedScrollingEnabled(boolean enabled)

Enable or disable nested scrolling for this view.

void setNextFocusDownId(int nextFocusDownId)

Sets the id of the view to use when the next focus is FOCUS_DOWN.

void setNextFocusForwardId(int nextFocusForwardId)

Sets the id of the view to use when the next focus is FOCUS_FORWARD.

void setNextFocusLeftId(int nextFocusLeftId)

Sets the id of the view to use when the next focus is FOCUS_LEFT.

void setNextFocusRightId(int nextFocusRightId)

Sets the id of the view to use when the next focus is FOCUS_RIGHT.

void setNextFocusUpId(int nextFocusUpId)

Sets the id of the view to use when the next focus is FOCUS_UP.

void setOnApplyWindowInsetsListener(View.OnApplyWindowInsetsListener listener)

Set an View.OnApplyWindowInsetsListener to take over the policy for applying window insets to this view.

void setOnClickListener(View.OnClickListener l)

Register a callback to be invoked when this view is clicked.

void setOnContextClickListener(View.OnContextClickListener l)

Register a callback to be invoked when this view is context clicked.

void setOnCreateContextMenuListener(View.OnCreateContextMenuListener l)

Register a callback to be invoked when the context menu for this view is being built.

void setOnDragListener(View.OnDragListener l)

Register a drag event listener callback object for this View.

void setOnFocusChangeListener(View.OnFocusChangeListener l)

Register a callback to be invoked when focus of this view changed.

void setOnGenericMotionListener(View.OnGenericMotionListener l)

Register a callback to be invoked when a generic motion event is sent to this view.

void setOnHoverListener(View.OnHoverListener l)

Register a callback to be invoked when a hover event is sent to this view.

void setOnKeyListener(View.OnKeyListener l)

Register a callback to be invoked when a hardware key is pressed in this view.

void setOnLongClickListener(View.OnLongClickListener l)

Register a callback to be invoked when this view is clicked and held.

void setOnScrollChangeListener(View.OnScrollChangeListener l)

Register a callback to be invoked when the scroll X or Y positions of this view change.

void setOnSystemUiVisibilityChangeListener(View.OnSystemUiVisibilityChangeListener l)

Set a listener to receive callbacks when the visibility of the system bar changes.

void setOnTouchListener(View.OnTouchListener l)

Register a callback to be invoked when a touch event is sent to this view.

void setOutlineProvider(ViewOutlineProvider provider)

Sets the ViewOutlineProvider of the view, which generates the Outline that defines the shape of the shadow it casts, and enables outline clipping.

void setOverScrollMode(int overScrollMode)

Set the over-scroll mode for this view.

void setPadding(int left, int top, int right, int bottom)

Sets the padding.

void setPaddingRelative(int start, int top, int end, int bottom)

Sets the relative padding.

void setPivotX(float pivotX)

Sets the x location of the point around which the view is rotated and scaled.

void setPivotY(float pivotY)

Sets the y location of the point around which the view is rotated and scaled.

void setPointerIcon(PointerIcon pointerIcon)

Set the pointer icon for the current view.

void setPressed(boolean pressed)

Sets the pressed state for this view.

final void setRight(int right)

Sets the right position of this view relative to its parent.

void setRotation(float rotation)

Sets the degrees that the view is rotated around the pivot point.

void setRotationX(float rotationX)

Sets the degrees that the view is rotated around the horizontal axis through the pivot point.

void setRotationY(float rotationY)

Sets the degrees that the view is rotated around the vertical axis through the pivot point.

void setSaveEnabled(boolean enabled)

Controls whether the saving of this view's state is enabled (that is, whether its onSaveInstanceState() method will be called).

void setSaveFromParentEnabled(boolean enabled)

Controls whether the entire hierarchy under this view will save its state when a state saving traversal occurs from its parent.

void setScaleX(float scaleX)

Sets the amount that the view is scaled in x around the pivot point, as a proportion of the view's unscaled width.

void setScaleY(float scaleY)

Sets the amount that the view is scaled in Y around the pivot point, as a proportion of the view's unscaled width.

void setScrollBarDefaultDelayBeforeFade(int scrollBarDefaultDelayBeforeFade)

Define the delay before scrollbars fade.

void setScrollBarFadeDuration(int scrollBarFadeDuration)

Define the scrollbar fade duration.

void setScrollBarSize(int scrollBarSize)

Define the scrollbar size.

void setScrollBarStyle(int style)

Specify the style of the scrollbars.

void setScrollContainer(boolean isScrollContainer)

Change whether this view is one of the set of scrollable containers in its window.

void setScrollIndicators(int indicators, int mask)

Sets the state of the scroll indicators specified by the mask.

void setScrollIndicators(int indicators)

Sets the state of all scroll indicators.

void setScrollX(int value)

Set the horizontal scrolled position of your view.

void setScrollY(int value)

Set the vertical scrolled position of your view.

void setScrollbarFadingEnabled(boolean fadeScrollbars)

Define whether scrollbars will fade when the view is not scrolling.

void setSelected(boolean selected)

Changes the selection state of this view.

void setSoundEffectsEnabled(boolean soundEffectsEnabled)

Set whether this view should have sound effects enabled for events such as clicking and touching.

void setStateListAnimator(StateListAnimator stateListAnimator)

Attaches the provided StateListAnimator to this View.

void setSystemUiVisibility(int visibility)

Request that the visibility of the status bar or other screen/window decorations be changed.

void setTag(int key, Object tag)

Sets a tag associated with this view and a key.

void setTag(Object tag)

Sets the tag associated with this view.

void setTextAlignment(int textAlignment)

Set the text alignment.

void setTextDirection(int textDirection)

Set the text direction.

final void setTop(int top)

Sets the top position of this view relative to its parent.

void setTouchDelegate(TouchDelegate delegate)

Sets the TouchDelegate for this View.

final void setTransitionName(String transitionName)

Sets the name of the View to be used to identify Views in Transitions.

void setTranslationX(float translationX)

Sets the horizontal location of this view relative to its left position.

void setTranslationY(float translationY)

Sets the vertical location of this view relative to its top position.

void setTranslationZ(float translationZ)

Sets the depth location of this view relative to its elevation.

void setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled)

Define whether the vertical edges should be faded when this view is scrolled vertically.

void setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled)

Define whether the vertical scrollbar should be drawn or not.

void setVerticalScrollbarPosition(int position)

Set the position of the vertical scroll bar.

void setVisibility(int visibility)

Set the enabled state of this view.

void setWillNotCacheDrawing(boolean willNotCacheDrawing)

When a View's drawing cache is enabled, drawing is redirected to an offscreen bitmap.

void setWillNotDraw(boolean willNotDraw)

If this view doesn't do any drawing on its own, set this flag to allow further optimizations.

void setX(float x)

Sets the visual x position of this view, in pixels.

void setY(float y)

Sets the visual y position of this view, in pixels.

void setZ(float z)

Sets the visual z position of this view, in pixels.

boolean showContextMenu()

Shows the context menu for this view.

boolean showContextMenu(float x, float y)

Shows the context menu for this view anchored to the specified view-relative coordinate.

ActionMode startActionMode(ActionMode.Callback callback, int type)

Start an action mode with the given type.

ActionMode startActionMode(ActionMode.Callback callback)

Start an action mode with the default type TYPE_PRIMARY.

void startAnimation(Animation animation)

Start the specified animation now.

final boolean startDrag(ClipData data, View.DragShadowBuilder shadowBuilder, Object myLocalState, int flags)

This method was deprecated in API level 24. Use startDragAndDrop() for newer platform versions.

final boolean startDragAndDrop(ClipData data, View.DragShadowBuilder shadowBuilder, Object myLocalState, int flags)

Starts a drag and drop operation.

boolean startNestedScroll(int axes)

Begin a nestable scroll operation along the given axes.

void stopNestedScroll()

Stop a nested scroll in progress.

String toString()

Returns a string representation of the object.

void unscheduleDrawable(Drawable who, Runnable what)

Cancels a scheduled action on a drawable.

void unscheduleDrawable(Drawable who)

Unschedule any events associated with the given Drawable.

final void updateDragShadow(View.DragShadowBuilder shadowBuilder)

Updates the drag shadow for the ongoing drag and drop operation.

boolean willNotCacheDrawing()

Returns whether or not this View can cache its drawing or not.

boolean willNotDraw()

Returns whether or not this View draws on its own.

Protected methods

boolean awakenScrollBars(int startDelay, boolean invalidate)

Trigger the scrollbars to draw.

boolean awakenScrollBars(int startDelay)

Trigger the scrollbars to draw.

boolean awakenScrollBars()

Trigger the scrollbars to draw.

int computeHorizontalScrollExtent()

Compute the horizontal extent of the horizontal scrollbar's thumb within the horizontal range.

int computeHorizontalScrollOffset()

Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range.

int computeHorizontalScrollRange()

Compute the horizontal range that the horizontal scrollbar represents.

int computeVerticalScrollExtent()

Compute the vertical extent of the vertical scrollbar's thumb within the vertical range.

int computeVerticalScrollOffset()

Compute the vertical offset of the vertical scrollbar's thumb within the horizontal range.

int computeVerticalScrollRange()

Compute the vertical range that the vertical scrollbar represents.

void dispatchDraw(Canvas canvas)

Called by draw to draw the child views.

boolean dispatchGenericFocusedEvent(MotionEvent event)

Dispatch a generic motion event to the currently focused view.

boolean dispatchGenericPointerEvent(MotionEvent event)

Dispatch a generic motion event to the view under the first pointer.

boolean dispatchHoverEvent(MotionEvent event)

Dispatch a hover event.

void dispatchRestoreInstanceState(SparseArray<Parcelable> container)

Called by restoreHierarchyState(android.util.SparseArray) to retrieve the state for this view and its children.

void dispatchSaveInstanceState(SparseArray<Parcelable> container)

Called by saveHierarchyState(android.util.SparseArray) to store the state for this view and its children.

void dispatchSetActivated(boolean activated)

Dispatch setActivated to all of this View's children.

void dispatchSetPressed(boolean pressed)

Dispatch setPressed to all of this View's children.

void dispatchSetSelected(boolean selected)

Dispatch setSelected to all of this View's children.

void dispatchVisibilityChanged(View changedView, int visibility)

Dispatch a view visibility change down the view hierarchy.

void drawableStateChanged()

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

boolean fitSystemWindows(Rect insets)

This method was deprecated in API level 20. As of API 20 use dispatchApplyWindowInsets(WindowInsets) to apply insets to views. Views should override onApplyWindowInsets(WindowInsets) or use setOnApplyWindowInsetsListener(android.view.View.OnApplyWindowInsetsListener) to implement handling their own insets.

float getBottomFadingEdgeStrength()

Returns the strength, or intensity, of the bottom faded edge.

int getBottomPaddingOffset()

Amount by which to extend the bottom fading region.

ContextMenu.ContextMenuInfo getContextMenuInfo()

Views should implement this if they have extra information to associate with the context menu.

int getHorizontalScrollbarHeight()

Returns the height of the horizontal scrollbar.

float getLeftFadingEdgeStrength()

Returns the strength, or intensity, of the left faded edge.

int getLeftPaddingOffset()

Amount by which to extend the left fading region.

float getRightFadingEdgeStrength()

Returns the strength, or intensity, of the right faded edge.

int getRightPaddingOffset()

Amount by which to extend the right fading region.

int getSuggestedMinimumHeight()

Returns the suggested minimum height that the view should use.

int getSuggestedMinimumWidth()

Returns the suggested minimum width that the view should use.

float getTopFadingEdgeStrength()

Returns the strength, or intensity, of the top faded edge.

int getTopPaddingOffset()

Amount by which to extend the top fading region.

int getWindowAttachCount()
boolean isPaddingOffsetRequired()

If the View draws content inside its padding and enables fading edges, it needs to support padding offsets.

static int[] mergeDrawableStates(int[] baseState, int[] additionalState)

Merge your own state values in additionalState into the base state values baseState that were returned by onCreateDrawableState(int).

void onAnimationEnd()

Invoked by a parent ViewGroup to notify the end of the animation currently associated with this view.

void onAnimationStart()

Invoked by a parent ViewGroup to notify the start of the animation currently associated with this view.

void onAttachedToWindow()

This is called when the view is attached to a window.

void onConfigurationChanged(Configuration newConfig)

Called when the current configuration of the resources being used by the application have changed.

void onCreateContextMenu(ContextMenu menu)

Views should implement this if the view itself is going to add items to the context menu.

int[] onCreateDrawableState(int extraSpace)

Generate the new Drawable state for this view.

void onDetachedFromWindow()

This is called when the view is detached from a window.

void onDisplayHint(int hint)

Gives this view a hint about whether is displayed or not.

void onDraw(Canvas canvas)

Implement this to do your drawing.

final void onDrawScrollBars(Canvas canvas)

Request the drawing of the horizontal and the vertical scrollbar.

void onFinishInflate()

Finalize inflating a view from XML.

void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)

Called by the view system when the focus state of this view changes.

void onLayout(boolean changed, int left, int top, int right, int bottom)

Called from layout when this view should assign a size and position to each of its children.

void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY)

Called by overScrollBy(int, int, int, int, int, int, int, int, boolean) to respond to the results of an over-scroll operation.

void onRestoreInstanceState(Parcelable state)

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState().

Parcelable onSaveInstanceState()

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state.

void onScrollChanged(int l, int t, int oldl, int oldt)

This is called in response to an internal scroll in this view (i.e., the view scrolled its own contents).

boolean onSetAlpha(int alpha)

Invoked if there is a Transform that involves alpha.

void onSizeChanged(int w, int h, int oldw, int oldh)

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

void onVisibilityChanged(View changedView, int visibility)

Called when the visibility of the view or an ancestor of the view has changed.

void onWindowVisibilityChanged(int visibility)

Called when the window containing has change its visibility (between GONE, INVISIBLE, and VISIBLE).

boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent)

Scroll the view with standard behavior for scrolling beyond the normal content boundaries.

final void setMeasuredDimension(int measuredWidth, int measuredHeight)

This method must be called by onMeasure(int, int) to store the measured width and measured height.

boolean verifyDrawable(Drawable who)

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying.

Inherited methods

From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

XML attributes

android:accessibilityLiveRegion

Indicates to accessibility services whether the user should be notified when this view changes.

May be an integer value, such as "100".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

May be one of the following constant values.

ConstantValueDescription
none0 Accessibility services should not announce changes to this view.
polite1 Accessibility services should announce changes to this view.
assertive2 Accessibility services should interrupt ongoing speech to immediately announce changes to this view.

This corresponds to the global attribute resource symbol accessibilityLiveRegion.

Related methods:

android:accessibilityTraversalAfter

Sets the id of a view after which this one is visited in accessibility traversal. A screen-reader must visit the content of the other view before the content of this one.

Related methods:

android:accessibilityTraversalBefore

Sets the id of a view before which this one is visited in accessibility traversal. A screen-reader must visit the content of this view before the content of the one it precedes.

Related methods:

android:alpha

alpha property of the view, as a value between 0 (completely transparent) and 1 (completely opaque).

Must be a floating point value, such as "1.2".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol alpha.

Related methods:

android:background

A drawable to use as the background. This can be either a reference to a full drawable resource (such as a PNG image, 9-patch, XML state list description, etc), or a solid color such as "#ff000000" (black).

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

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

This corresponds to the global attribute resource symbol background.

Related methods:

android:backgroundTint

Tint to apply to the background.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol backgroundTint.

Related methods:

android:backgroundTintMode

Blending mode used to apply the background tint.

Must be one of the following constant values.

ConstantValueDescription
src_over3 The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]
src_in5 The tint is masked by the alpha channel of the drawable. The drawable’s color channels are thrown out. [Sa * Da, Sc * Da]
src_atop9 The tint is drawn above the drawable, but with the drawable’s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
multiply14 Multiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screen15 [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
add16 Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)

This corresponds to the global attribute resource symbol backgroundTintMode.

Related methods:

android:clickable

Defines whether this view reacts to click events.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol clickable.

Related methods:

android:contentDescription

Defines text that briefly describes content of the view. This property is used primarily for accessibility. Since some views do not have textual representation this attribute can be used for providing such.

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol contentDescription.

Related methods:

android:contextClickable

Defines whether this view reacts to context click events.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol contextClickable.

Related methods:

android:drawingCacheQuality

Defines the quality of translucent drawing caches. This property is used only when the drawing cache is enabled and translucent. The default value is auto.

Must be one of the following constant values.

ConstantValueDescription
auto0 Lets the framework decide what quality level should be used for the drawing cache.
low1 Low quality. When set to low quality, the drawing cache uses a lower color depth, thus losing precision in rendering gradients, but uses less memory.
high2 High quality. When set to high quality, the drawing cache uses a higher color depth but uses more memory.

This corresponds to the global attribute resource symbol drawingCacheQuality.

Related methods:

android:duplicateParentState

When this attribute is set to true, the view gets its drawable state (focused, pressed, etc.) from its direct parent rather than from itself.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol duplicateParentState.

android:elevation

base z depth of the view

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol elevation.

Related methods:

android:fadeScrollbars

Defines whether to fade out scrollbars when they are not in use.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol fadeScrollbars.

Related methods:

android:fadingEdgeLength

Defines the length of the fading edges.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol fadingEdgeLength.

Related methods:

android:filterTouchesWhenObscured

Specifies whether to filter touches when the view's window is obscured by another visible window. When set to true, the view will not receive touches whenever a toast, dialog or other window appears above the view's window. Refer to the View security documentation for more details.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol filterTouchesWhenObscured.

Related methods:

android:fitsSystemWindows

Boolean internal attribute to adjust view layout based on system windows such as the status bar. If true, adjusts the padding of this view to leave space for the system windows. Will only take effect if this view is in a non-embedded activity.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol fitsSystemWindows.

Related methods:

android:focusable

Boolean that controls whether a view can take focus. By default the user can not move focus to a view; by setting this attribute to true the view is allowed to take focus. This value does not impact the behavior of directly calling requestFocus(), which will always request focus regardless of this view. It only impacts where focus navigation will try to move focus.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol focusable.

Related methods:

android:focusableInTouchMode

Boolean that controls whether a view can take focus while in touch mode. If this is true for a view, that view can gain focus when clicked on, and can keep focus if another view is clicked on that doesn't have this attribute set to true.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol focusableInTouchMode.

Related methods:

android:forceHasOverlappingRendering

Whether this view has elements that may overlap when drawn. See forceHasOverlappingRendering(boolean).

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol forceHasOverlappingRendering.

Related methods:

android:foreground

Defines the drawable to draw over the content. This can be used as an overlay. The foreground drawable participates in the padding of the content if the gravity is set to fill.

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

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

This corresponds to the global attribute resource symbol foreground.

Related methods:

android:foregroundGravity

Defines the gravity to apply to the foreground drawable. The gravity defaults to fill.

Must be one or more (separated by '|') of the following constant values.

ConstantValueDescription
top0x30 Push object to the top of its container, not changing its size.
bottom0x50 Push object to the bottom of its container, not changing its size.
left0x03 Push object to the left of its container, not changing its size.
right0x05 Push object to the right of its container, not changing its size.
center_vertical0x10 Place object in the vertical center of its container, not changing its size.
fill_vertical0x70 Grow the vertical size of the object if needed so it completely fills its container.
center_horizontal0x01 Place object in the horizontal center of its container, not changing its size.
fill_horizontal0x07 Grow the horizontal size of the object if needed so it completely fills its container.
center0x11 Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.
fill0x77 Grow the horizontal and vertical size of the object if needed so it completely fills its container.
clip_vertical0x80 Additional option that can be set to have the top and/or bottom edges of the child clipped to its container's bounds. The clip will be based on the vertical gravity: a top gravity will clip the bottom edge, a bottom gravity will clip the top edge, and neither will clip both edges.
clip_horizontal0x08 Additional option that can be set to have the left and/or right edges of the child clipped to its container's bounds. The clip will be based on the horizontal gravity: a left gravity will clip the right edge, a right gravity will clip the left edge, and neither will clip both edges.

This corresponds to the global attribute resource symbol foregroundGravity.

Related methods:

android:foregroundTint

Tint to apply to the foreground.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol foregroundTint.

Related methods:

android:foregroundTintMode

Blending mode used to apply the foreground tint.

Must be one of the following constant values.

ConstantValueDescription
src_over3 The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]
src_in5 The tint is masked by the alpha channel of the drawable. The drawable’s color channels are thrown out. [Sa * Da, Sc * Da]
src_atop9 The tint is drawn above the drawable, but with the drawable’s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
multiply14 Multiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screen15 [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
add16 Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)

This corresponds to the global attribute resource symbol foregroundTintMode.

Related methods:

android:hapticFeedbackEnabled

Boolean that controls whether a view should have haptic feedback enabled for events such as long presses.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol hapticFeedbackEnabled.

Related methods:

android:id

Supply an identifier name for this view, to later retrieve it with View.findViewById() or Activity.findViewById(). This must be a resource reference; typically you set this using the @+ syntax to create a new ID resources. For example: android:id="@+id/my_id" which allows you to later retrieve the view with findViewById(R.id.my_id).

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

This corresponds to the global attribute resource symbol id.

Related methods:

android:importantForAccessibility

Controls how this View is important for accessibility which is if it fires accessibility events and if it is reported to accessibility services that query the screen. Note: While not recommended, an accessibility service may decide to ignore this attribute and operate on all views in the view tree.

May be an integer value, such as "100".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

May be one of the following constant values.

ConstantValueDescription
auto0 The system determines whether the view is important for accessibility - default (recommended).
yes1 The view is important for accessibility.
no2 The view is not important for accessibility.
noHideDescendants4 The view is not important for accessibility, nor are any of its descendant views.

This corresponds to the global attribute resource symbol importantForAccessibility.

Related methods:

android:isScrollContainer

Set this if the view will serve as a scrolling container, meaning that it can be resized to shrink its overall window so that there will be space for an input method. If not set, the default value will be true if "scrollbars" has the vertical scrollbar set, else it will be false.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol isScrollContainer.

Related methods:

android:keepScreenOn

Controls whether the view's window should keep the screen on while visible.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol keepScreenOn.

Related methods:

android:layerType

Specifies the type of layer backing this view. The default value is none. Refer to setLayerType(int, android.graphics.Paint) for more information.

Must be one of the following constant values.

ConstantValueDescription
none0 Don't use a layer.
software1 Use a software layer. Refer to setLayerType(int, android.graphics.Paint) for more information.
hardware2 Use a hardware layer. Refer to setLayerType(int, android.graphics.Paint) for more information.

This corresponds to the global attribute resource symbol layerType.

Related methods:

android:layoutDirection

Defines the direction of layout drawing. This typically is associated with writing direction of the language script used. The possible values are "ltr" for Left-to-Right, "rtl" for Right-to-Left, "locale" and "inherit" from parent view. If there is nothing to inherit, "locale" is used. "locale" falls back to "en-US". "ltr" is the direction used in "en-US". The default for this attribute is "inherit".

Must be one of the following constant values.

ConstantValueDescription
ltr0 Left-to-Right
rtl1 Right-to-Left
inherit2 Inherit from parent
locale3 Locale

This corresponds to the global attribute resource symbol layoutDirection.

Related methods:

android:longClickable

Defines whether this view reacts to long click events.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol longClickable.

Related methods:

android:minHeight

Defines the minimum height of the view. It is not guaranteed the view will be able to achieve this minimum height (for example, if its parent layout constrains it with less available height).

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol minHeight.

Related methods:

android:minWidth

Defines the minimum width of the view. It is not guaranteed the view will be able to achieve this minimum width (for example, if its parent layout constrains it with less available width).

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol minWidth.

Related methods:

android:nextFocusDown

Defines the next view to give focus to when the next focus is FOCUS_DOWN If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed.

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

This corresponds to the global attribute resource symbol nextFocusDown.

Related methods:

android:nextFocusForward

Defines the next view to give focus to when the next focus is FOCUS_FORWARD If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed.

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

This corresponds to the global attribute resource symbol nextFocusForward.

Related methods:

android:nextFocusLeft

Defines the next view to give focus to when the next focus is FOCUS_LEFT. If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed.

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

This corresponds to the global attribute resource symbol nextFocusLeft.

Related methods:

android:nextFocusRight

Defines the next view to give focus to when the next focus is FOCUS_RIGHT If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed.

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

This corresponds to the global attribute resource symbol nextFocusRight.

Related methods:

android:nextFocusUp

Defines the next view to give focus to when the next focus is FOCUS_UP If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed.

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

This corresponds to the global attribute resource symbol nextFocusUp.

Related methods:

android:onClick

Name of the method in this View's context to invoke when the view is clicked. This name must correspond to a public method that takes exactly one parameter of type View. For instance, if you specify android:onClick="sayHello", you must declare a public void sayHello(View v) method of your context (typically, your Activity).

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol onClick.

android:padding

Sets the padding, in pixels, of all four edges. Padding is defined as space between the edges of the view and the view's content. A views size will include it's padding. If a background is provided, the padding will initially be set to that (0 if the drawable does not have padding). Explicitly setting a padding value will override the corresponding padding found in the background.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol padding.

Related methods:

android:paddingBottom

Sets the padding, in pixels, of the bottom edge; see padding.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol paddingBottom.

Related methods:

android:paddingEnd

Sets the padding, in pixels, of the end edge; see padding.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol paddingEnd.

Related methods:

android:paddingLeft

Sets the padding, in pixels, of the left edge; see padding.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol paddingLeft.

Related methods:

android:paddingRight

Sets the padding, in pixels, of the right edge; see padding.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol paddingRight.

Related methods:

android:paddingStart

Sets the padding, in pixels, of the start edge; see padding.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol paddingStart.

Related methods:

android:paddingTop

Sets the padding, in pixels, of the top edge; see padding.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol paddingTop.

Related methods:

android:requiresFadingEdge

Defines which edges should be faded on scrolling.

Must be one or more (separated by '|') of the following constant values.

ConstantValueDescription
none0x00000000 No edge is faded.
horizontal0x00001000 Fades horizontal edges only.
vertical0x00002000 Fades vertical edges only.

This corresponds to the global attribute resource symbol requiresFadingEdge.

Related methods:

android:rotation

rotation of the view, in degrees.

Must be a floating point value, such as "1.2".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol rotation.

Related methods:

android:rotationX

rotation of the view around the x axis, in degrees.

Must be a floating point value, such as "1.2".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol rotationX.

Related methods:

android:rotationY

rotation of the view around the y axis, in degrees.

Must be a floating point value, such as "1.2".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol rotationY.

Related methods:

android:saveEnabled

If false, no state will be saved for this view when it is being frozen. The default is true, allowing the view to be saved (however it also must have an ID assigned to it for its state to be saved). Setting this to false only disables the state for this view, not for its children which may still be saved.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol saveEnabled.

Related methods:

android:scaleX

scale of the view in the x direction.

Must be a floating point value, such as "1.2".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scaleX.

Related methods:

android:scaleY

scale of the view in the y direction.

Must be a floating point value, such as "1.2".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scaleY.

Related methods:

android:scrollIndicators

Defines which scroll indicators should be displayed when the view can be scrolled. Multiple values may be combined using logical OR, for example "top|bottom".

Must be one or more (separated by '|') of the following constant values.

ConstantValueDescription
none0x00 No scroll indicators are displayed.
top0x01 Displays top scroll indicator when view can be scrolled up.
bottom0x02 Displays bottom scroll indicator when vew can be scrolled down.
left0x04 Displays left scroll indicator when vew can be scrolled left.
right0x08 Displays right scroll indicator when vew can be scrolled right.
start0x10 Displays right scroll indicator when vew can be scrolled in the start direction.
end0x20 Displays right scroll indicator when vew can be scrolled in the end direction.

This corresponds to the global attribute resource symbol scrollIndicators.

Related methods:

android:scrollX

The initial horizontal scroll offset, in pixels.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scrollX.

android:scrollY

The initial vertical scroll offset, in pixels.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scrollY.

android:scrollbarAlwaysDrawHorizontalTrack

Defines whether the horizontal scrollbar track should always be drawn.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scrollbarAlwaysDrawHorizontalTrack.

android:scrollbarAlwaysDrawVerticalTrack

Defines whether the vertical scrollbar track should always be drawn.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scrollbarAlwaysDrawVerticalTrack.

android:scrollbarDefaultDelayBeforeFade

Defines the delay in milliseconds that a scrollbar waits before fade out.

Must be an integer value, such as "100".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scrollbarDefaultDelayBeforeFade.

Related methods:

android:scrollbarFadeDuration

Defines the delay in milliseconds that a scrollbar takes to fade out.

Must be an integer value, such as "100".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scrollbarFadeDuration.

Related methods:

android:scrollbarSize

Sets the width of vertical scrollbars and height of horizontal scrollbars.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol scrollbarSize.

Related methods:

android:scrollbarStyle

Controls the scrollbar style and position. The scrollbars can be overlaid or inset. When inset, they add to the padding of the view. And the scrollbars can be drawn inside the padding area or on the edge of the view. For example, if a view has a background drawable and you want to draw the scrollbars inside the padding specified by the drawable, you can use insideOverlay or insideInset. If you want them to appear at the edge of the view, ignoring the padding, then you can use outsideOverlay or outsideInset.

Must be one of the following constant values.

ConstantValueDescription
insideOverlay0x0 Inside the padding and overlaid
insideInset0x01000000 Inside the padding and inset
outsideOverlay0x02000000 Edge of the view and overlaid
outsideInset0x03000000 Edge of the view and inset

This corresponds to the global attribute resource symbol scrollbarStyle.

Related methods:

android:scrollbarThumbHorizontal

Defines the horizontal scrollbar thumb drawable.

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

This corresponds to the global attribute resource symbol scrollbarThumbHorizontal.

android:scrollbarThumbVertical

Defines the vertical scrollbar thumb drawable.

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

This corresponds to the global attribute resource symbol scrollbarThumbVertical.

android:scrollbarTrackHorizontal

Defines the horizontal scrollbar track drawable.

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

This corresponds to the global attribute resource symbol scrollbarTrackHorizontal.

android:scrollbarTrackVertical

Defines the vertical scrollbar track drawable.

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

This corresponds to the global attribute resource symbol scrollbarTrackVertical.

android:scrollbars

Defines which scrollbars should be displayed on scrolling or not.

Must be one or more (separated by '|') of the following constant values.

ConstantValueDescription
none0x00000000 No scrollbar is displayed.
horizontal0x00000100 Displays horizontal scrollbar only.
vertical0x00000200 Displays vertical scrollbar only.

This corresponds to the global attribute resource symbol scrollbars.

android:soundEffectsEnabled

Boolean that controls whether a view should have sound effects enabled for events such as clicking and touching.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol soundEffectsEnabled.

Related methods:

android:stateListAnimator

Sets the state-based animator for the View.

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

This corresponds to the global attribute resource symbol stateListAnimator.

android:tag

Supply a tag for this view containing a String, to be retrieved later with View.getTag() or searched for with View.findViewWithTag(). It is generally preferable to use IDs (through the android:id attribute) instead of tags because they are faster and allow for compile-time type checking.

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol tag.

android:textAlignment

Defines the alignment of the text. A heuristic is used to determine the resolved text alignment.

May be an integer value, such as "100".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

May be one of the following constant values.

ConstantValueDescription
inherit0 Default
gravity1 Default for the root view. The gravity determines the alignment, ALIGN_NORMAL, ALIGN_CENTER, or ALIGN_OPPOSITE, which are relative to each paragraph’s text direction
textStart2 Align to the start of the paragraph, e.g. ALIGN_NORMAL.
textEnd3 Align to the end of the paragraph, e.g. ALIGN_OPPOSITE.
center4 Center the paragraph, e.g. ALIGN_CENTER.
viewStart5 Align to the start of the view, which is ALIGN_LEFT if the view’s resolved layoutDirection is LTR, and ALIGN_RIGHT otherwise.
viewEnd6 Align to the end of the view, which is ALIGN_RIGHT if the view’s resolved layoutDirection is LTR, and ALIGN_LEFT otherwise

This corresponds to the global attribute resource symbol textAlignment.

Related methods:

android:textDirection

Defines the direction of the text. A heuristic is used to determine the resolved text direction of paragraphs.

May be an integer value, such as "100".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

May be one of the following constant values.

ConstantValueDescription
inherit0 Default
firstStrong1 Default for the root view. The first strong directional character determines the paragraph direction. If there is no strong directional character, the paragraph direction is the view’s resolved layout direction.
anyRtl2 The paragraph direction is RTL if it contains any strong RTL character, otherwise it is LTR if it contains any strong LTR characters. If there are neither, the paragraph direction is the view’s resolved layout direction.
ltr3 The paragraph direction is left to right.
rtl4 The paragraph direction is right to left.
locale5 The paragraph direction is coming from the system Locale.
firstStrongLtr6 The first strong directional character determines the paragraph direction. If there is no strong directional character, the paragraph direction is LTR.
firstStrongRtl7 The first strong directional character determines the paragraph direction. If there is no strong directional character, the paragraph direction is RTL.

This corresponds to the global attribute resource symbol textDirection.

Related methods:

android:theme

Specifies a theme override for a view. When a theme override is set, the view will be inflated using a Context themed with the specified resource. During XML inflation, any child views under the view with a theme override will inherit the themed context.

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

This corresponds to the global attribute resource symbol theme.

android:transformPivotX

x location of the pivot point around which the view will rotate and scale. This xml attribute sets the pivotX property of the View.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol transformPivotX.

Related methods:

android:transformPivotY

y location of the pivot point around which the view will rotate and scale. This xml attribute sets the pivotY property of the View.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol transformPivotY.

Related methods:

android:transitionName

Names a View such that it can be identified for Transitions. Names should be unique in the View hierarchy.

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol transitionName.

android:translationX

translation in x of the view. This value is added post-layout to the left property of the view, which is set by its layout.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol translationX.

Related methods:

android:translationY

translation in y of the view. This value is added post-layout to the top property of the view, which is set by its layout.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol translationY.

Related methods:

android:translationZ

translation in z of the view. This value is added to its elevation.

Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol translationZ.

Related methods:

android:visibility

Controls the initial visibility of the view.

Must be one of the following constant values.

ConstantValueDescription
visible0 Visible on screen; the default value.
invisible1 Not displayed, but taken into account during layout (space is left for it).
gone2 Completely hidden, as if the view had not been added.

This corresponds to the global attribute resource symbol visibility.

Related methods:

Constants

ACCESSIBILITY_LIVE_REGION_ASSERTIVE

Added in API level 19
int ACCESSIBILITY_LIVE_REGION_ASSERTIVE

Live region mode specifying that accessibility services should interrupt ongoing speech to immediately announce changes to this view.

Use with setAccessibilityLiveRegion(int).

Constant Value: 2 (0x00000002)

ACCESSIBILITY_LIVE_REGION_NONE

Added in API level 19
int ACCESSIBILITY_LIVE_REGION_NONE

Live region mode specifying that accessibility services should not automatically announce changes to this view. This is the default live region mode for most views.

Use with setAccessibilityLiveRegion(int).

Constant Value: 0 (0x00000000)

ACCESSIBILITY_LIVE_REGION_POLITE

Added in API level 19
int ACCESSIBILITY_LIVE_REGION_POLITE

Live region mode specifying that accessibility services should announce changes to this view.

Use with setAccessibilityLiveRegion(int).

Constant Value: 1 (0x00000001)

DRAG_FLAG_GLOBAL

Added in API level 24
int DRAG_FLAG_GLOBAL

Flag indicating that a drag can cross window boundaries. When startDragAndDrop(ClipData, DragShadowBuilder, Object, int) is called with this flag set, all visible applications with targetSdkVersion >= API 24 will be able to participate in the drag operation and receive the dragged content. If this is the only flag set, then the drag recipient will only have access to text data and intents contained in the ClipData object. Access to URIs contained in the ClipData is determined by other DRAG_FLAG_GLOBAL_* flags.

Constant Value: 256 (0x00000100)

DRAG_FLAG_GLOBAL_PERSISTABLE_URI_PERMISSION

Added in API level 24
int DRAG_FLAG_GLOBAL_PERSISTABLE_URI_PERMISSION

When this flag is used with DRAG_FLAG_GLOBAL_URI_READ and/or DRAG_FLAG_GLOBAL_URI_WRITE, the URI permission grant can be persisted across device reboots until explicitly revoked with Context.revokeUriPermission.

See also:

Constant Value: 64 (0x00000040)

DRAG_FLAG_GLOBAL_PREFIX_URI_PERMISSION

Added in API level 24
int DRAG_FLAG_GLOBAL_PREFIX_URI_PERMISSION

When this flag is used with DRAG_FLAG_GLOBAL_URI_READ and/or DRAG_FLAG_GLOBAL_URI_WRITE, the URI permission grant applies to any URI that is a prefix match against the original granted URI.

See also:

Constant Value: 128 (0x00000080)

DRAG_FLAG_GLOBAL_URI_READ

Added in API level 24
int DRAG_FLAG_GLOBAL_URI_READ

When this flag is used with DRAG_FLAG_GLOBAL, the drag recipient will be able to request read access to the content URI(s) contained in the ClipData object.

See also:

Constant Value: 1 (0x00000001)

DRAG_FLAG_GLOBAL_URI_WRITE

Added in API level 24
int DRAG_FLAG_GLOBAL_URI_WRITE

When this flag is used with DRAG_FLAG_GLOBAL, the drag recipient will be able to request write access to the content URI(s) contained in the ClipData object.

See also:

Constant Value: 2 (0x00000002)

DRAG_FLAG_OPAQUE

Added in API level 24
int DRAG_FLAG_OPAQUE

Flag indicating that the drag shadow will be opaque. When startDragAndDrop(ClipData, DragShadowBuilder, Object, int) is called with this flag set, the drag shadow will be opaque, otherwise, it will be semitransparent.

Constant Value: 512 (0x00000200)

DRAWING_CACHE_QUALITY_AUTO

Added in API level 1
int DRAWING_CACHE_QUALITY_AUTO

Enables automatic quality mode for the drawing cache.

Constant Value: 0 (0x00000000)

DRAWING_CACHE_QUALITY_HIGH

Added in API level 1
int DRAWING_CACHE_QUALITY_HIGH

Enables high quality mode for the drawing cache.

Constant Value: 1048576 (0x00100000)

DRAWING_CACHE_QUALITY_LOW

Added in API level 1
int DRAWING_CACHE_QUALITY_LOW

Enables low quality mode for the drawing cache.

Constant Value: 524288 (0x00080000)

FIND_VIEWS_WITH_CONTENT_DESCRIPTION

Added in API level 14
int FIND_VIEWS_WITH_CONTENT_DESCRIPTION

Find find views that contain the specified content description.

See also:

Constant Value: 2 (0x00000002)

FIND_VIEWS_WITH_TEXT

Added in API level 14
int FIND_VIEWS_WITH_TEXT

Find views that render the specified text.

See also:

Constant Value: 1 (0x00000001)

FOCUSABLES_ALL

Added in API level 4
int FOCUSABLES_ALL

View flag indicating whether addFocusables(ArrayList, int, int) should add all focusable Views regardless if they are focusable in touch mode.

Constant Value: 0 (0x00000000)

FOCUSABLES_TOUCH_MODE

Added in API level 4
int FOCUSABLES_TOUCH_MODE

View flag indicating whether addFocusables(ArrayList, int, int) should add only Views focusable in touch mode.

Constant Value: 1 (0x00000001)

FOCUS_BACKWARD

Added in API level 1
int FOCUS_BACKWARD

Use with focusSearch(int). Move focus to the previous selectable item.

Constant Value: 1 (0x00000001)

FOCUS_DOWN

Added in API level 1
int FOCUS_DOWN

Use with focusSearch(int). Move focus down.

Constant Value: 130 (0x00000082)

FOCUS_FORWARD

Added in API level 1
int FOCUS_FORWARD

Use with focusSearch(int). Move focus to the next selectable item.

Constant Value: 2 (0x00000002)

FOCUS_LEFT

Added in API level 1
int FOCUS_LEFT

Use with focusSearch(int). Move focus to the left.

Constant Value: 17 (0x00000011)

FOCUS_RIGHT

Added in API level 1
int FOCUS_RIGHT

Use with focusSearch(int). Move focus to the right.

Constant Value: 66 (0x00000042)

FOCUS_UP

Added in API level 1
int FOCUS_UP

Use with focusSearch(int). Move focus up.

Constant Value: 33 (0x00000021)

GONE

Added in API level 1
int GONE

This view is invisible, and it doesn't take any space for layout purposes. Use with setVisibility(int) and android:visibility.

Constant Value: 8 (0x00000008)

HAPTIC_FEEDBACK_ENABLED

Added in API level 3
int HAPTIC_FEEDBACK_ENABLED

View flag indicating whether this view should have haptic feedback enabled for events such as long presses.

Constant Value: 268435456 (0x10000000)

IMPORTANT_FOR_ACCESSIBILITY_AUTO

Added in API level 16
int IMPORTANT_FOR_ACCESSIBILITY_AUTO

Automatically determine whether a view is important for accessibility.

Constant Value: 0 (0x00000000)

IMPORTANT_FOR_ACCESSIBILITY_NO

Added in API level 16
int IMPORTANT_FOR_ACCESSIBILITY_NO

The view is not important for accessibility.

Constant Value: 2 (0x00000002)

IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS

Added in API level 19
int IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS

The view is not important for accessibility, nor are any of its descendant views.

Constant Value: 4 (0x00000004)

IMPORTANT_FOR_ACCESSIBILITY_YES

Added in API level 16
int IMPORTANT_FOR_ACCESSIBILITY_YES

The view is important for accessibility.

Constant Value: 1 (0x00000001)

INVISIBLE

Added in API level 1
int INVISIBLE

This view is invisible, but it still takes up space for layout purposes. Use with setVisibility(int) and android:visibility.

Constant Value: 4 (0x00000004)

KEEP_SCREEN_ON

Added in API level 1
int KEEP_SCREEN_ON

View flag indicating that the screen should remain on while the window containing this view is visible to the user. This effectively takes care of automatically setting the WindowManager's FLAG_KEEP_SCREEN_ON.

Constant Value: 67108864 (0x04000000)

LAYER_TYPE_HARDWARE

Added in API level 11
int LAYER_TYPE_HARDWARE

Indicates that the view has a hardware layer. A hardware layer is backed by a hardware specific texture (generally Frame Buffer Objects or FBO on OpenGL hardware) and causes the view to be rendered using Android's hardware rendering pipeline, but only if hardware acceleration is turned on for the view hierarchy. When hardware acceleration is turned off, hardware layers behave exactly as software layers.

A hardware layer is useful to apply a specific color filter and/or blending mode and/or translucency to a view and all its children.

A hardware layer can be used to cache a complex view tree into a texture and reduce the complexity of drawing operations. For instance, when animating a complex view tree with a translation, a hardware layer can be used to render the view tree only once.

A hardware layer can also be used to increase the rendering quality when rotation transformations are applied on a view. It can also be used to prevent potential clipping issues when applying 3D transforms on a view.

See also:

Constant Value: 2 (0x00000002)

LAYER_TYPE_NONE

Added in API level 11
int LAYER_TYPE_NONE

Indicates that the view does not have a layer.

See also:

Constant Value: 0 (0x00000000)

LAYER_TYPE_SOFTWARE

Added in API level 11
int LAYER_TYPE_SOFTWARE

Indicates that the view has a software layer. A software layer is backed by a bitmap and causes the view to be rendered using Android's software rendering pipeline, even if hardware acceleration is enabled.

Software layers have various usages:

When the application is not using hardware acceleration, a software layer is useful to apply a specific color filter and/or blending mode and/or translucency to a view and all its children.

When the application is using hardware acceleration, a software layer is useful to render drawing primitives not supported by the hardware accelerated pipeline. It can also be used to cache a complex view tree into a texture and reduce the complexity of drawing operations. For instance, when animating a complex view tree with a translation, a software layer can be used to render the view tree only once.

Software layers should be avoided when the affected view tree updates often. Every update will require to re-render the software layer, which can potentially be slow (particularly when hardware acceleration is turned on since the layer will have to be uploaded into a hardware texture after every update.)

See also:

Constant Value: 1 (0x00000001)

LAYOUT_DIRECTION_INHERIT

Added in API level 17
int LAYOUT_DIRECTION_INHERIT

Horizontal layout direction of this view is inherited from its parent. Use with setLayoutDirection(int).

Constant Value: 2 (0x00000002)

LAYOUT_DIRECTION_LOCALE

Added in API level 17
int LAYOUT_DIRECTION_LOCALE

Horizontal layout direction of this view is from deduced from the default language script for the locale. Use with setLayoutDirection(int).

Constant Value: 3 (0x00000003)

LAYOUT_DIRECTION_LTR

Added in API level 17
int LAYOUT_DIRECTION_LTR

Horizontal layout direction of this view is from Left to Right. Use with setLayoutDirection(int).

Constant Value: 0 (0x00000000)

LAYOUT_DIRECTION_RTL

Added in API level 17
int LAYOUT_DIRECTION_RTL

Horizontal layout direction of this view is from Right to Left. Use with setLayoutDirection(int).

Constant Value: 1 (0x00000001)

MEASURED_HEIGHT_STATE_SHIFT

Added in API level 11
int MEASURED_HEIGHT_STATE_SHIFT

Bit shift of MEASURED_STATE_MASK to get to the height bits for functions that combine both width and height into a single int, such as getMeasuredState() and the childState argument of resolveSizeAndState(int, int, int).

Constant Value: 16 (0x00000010)

MEASURED_SIZE_MASK

Added in API level 11
int MEASURED_SIZE_MASK

Bits of getMeasuredWidthAndState() and getMeasuredWidthAndState() that provide the actual measured size.

Constant Value: 16777215 (0x00ffffff)

MEASURED_STATE_MASK

Added in API level 11
int MEASURED_STATE_MASK

Bits of getMeasuredWidthAndState() and getMeasuredWidthAndState() that provide the additional state bits.

Constant Value: -16777216 (0xff000000)

MEASURED_STATE_TOO_SMALL

Added in API level 11
int MEASURED_STATE_TOO_SMALL

Bit of getMeasuredWidthAndState() and getMeasuredWidthAndState() that indicates the measured size is smaller that the space the view would like to have.

Constant Value: 16777216 (0x01000000)

NO_ID

Added in API level 1
int NO_ID

Used to mark a View that has no ID.

Constant Value: -1 (0xffffffff)

OVER_SCROLL_ALWAYS

Added in API level 9
int OVER_SCROLL_ALWAYS

Always allow a user to over-scroll this view, provided it is a view that can scroll.

See also:

Constant Value: 0 (0x00000000)

OVER_SCROLL_IF_CONTENT_SCROLLS

Added in API level 9
int OVER_SCROLL_IF_CONTENT_SCROLLS

Allow a user to over-scroll this view only if the content is large enough to meaningfully scroll, provided it is a view that can scroll.

See also:

Constant Value: 1 (0x00000001)

OVER_SCROLL_NEVER

Added in API level 9
int OVER_SCROLL_NEVER

Never allow a user to over-scroll this view.

See also:

Constant Value: 2 (0x00000002)

SCREEN_STATE_OFF

Added in API level 16
int SCREEN_STATE_OFF

Indicates that the screen has changed state and is now off.

See also:

Constant Value: 0 (0x00000000)

SCREEN_STATE_ON

Added in API level 16
int SCREEN_STATE_ON

Indicates that the screen has changed state and is now on.

See also:

Constant Value: 1 (0x00000001)

SCROLLBARS_INSIDE_INSET

Added in API level 1
int SCROLLBARS_INSIDE_INSET

The scrollbar style to display the scrollbars inside the padded area, increasing the padding of the view. The scrollbars will not overlap the content area of the view.

Constant Value: 16777216 (0x01000000)

SCROLLBARS_INSIDE_OVERLAY

Added in API level 1
int SCROLLBARS_INSIDE_OVERLAY

The scrollbar style to display the scrollbars inside the content area, without increasing the padding. The scrollbars will be overlaid with translucency on the view's content.

Constant Value: 0 (0x00000000)

SCROLLBARS_OUTSIDE_INSET

Added in API level 1
int SCROLLBARS_OUTSIDE_INSET

The scrollbar style to display the scrollbars at the edge of the view, increasing the padding of the view. The scrollbars will only overlap the background, if any.

Constant Value: 50331648 (0x03000000)

SCROLLBARS_OUTSIDE_OVERLAY

Added in API level 1
int SCROLLBARS_OUTSIDE_OVERLAY

The scrollbar style to display the scrollbars at the edge of the view, without increasing the padding. The scrollbars will be overlaid with translucency.

Constant Value: 33554432 (0x02000000)

SCROLLBAR_POSITION_DEFAULT

Added in API level 11
int SCROLLBAR_POSITION_DEFAULT

Position the scroll bar at the default position as determined by the system.

Constant Value: 0 (0x00000000)

SCROLLBAR_POSITION_LEFT

Added in API level 11
int SCROLLBAR_POSITION_LEFT

Position the scroll bar along the left edge.

Constant Value: 1 (0x00000001)

SCROLLBAR_POSITION_RIGHT

Added in API level 11
int SCROLLBAR_POSITION_RIGHT

Position the scroll bar along the right edge.

Constant Value: 2 (0x00000002)

SCROLL_AXIS_HORIZONTAL

Added in API level 21
int SCROLL_AXIS_HORIZONTAL

Indicates scrolling along the horizontal axis.

Constant Value: 1 (0x00000001)

SCROLL_AXIS_NONE

Added in API level 21
int SCROLL_AXIS_NONE

Indicates no axis of view scrolling.

Constant Value: 0 (0x00000000)

SCROLL_AXIS_VERTICAL

Added in API level 21
int SCROLL_AXIS_VERTICAL

Indicates scrolling along the vertical axis.

Constant Value: 2 (0x00000002)

SCROLL_INDICATOR_BOTTOM

Added in API level 23
int SCROLL_INDICATOR_BOTTOM

Scroll indicator direction for the bottom edge of the view.

See also:

Constant Value: 2 (0x00000002)

SCROLL_INDICATOR_END

Added in API level 23
int SCROLL_INDICATOR_END

Scroll indicator direction for the ending edge of the view.

Resolved according to the view's layout direction, see getLayoutDirection() for more information.

See also:

Constant Value: 32 (0x00000020)

SCROLL_INDICATOR_LEFT

Added in API level 23
int SCROLL_INDICATOR_LEFT

Scroll indicator direction for the left edge of the view.

See also:

Constant Value: 4 (0x00000004)

SCROLL_INDICATOR_RIGHT

Added in API level 23
int SCROLL_INDICATOR_RIGHT

Scroll indicator direction for the right edge of the view.

See also:

Constant Value: 8 (0x00000008)

SCROLL_INDICATOR_START

Added in API level 23
int SCROLL_INDICATOR_START

Scroll indicator direction for the starting edge of the view.

Resolved according to the view's layout direction, see getLayoutDirection() for more information.

See also:

Constant Value: 16 (0x00000010)

SCROLL_INDICATOR_TOP

Added in API level 23
int SCROLL_INDICATOR_TOP

Scroll indicator direction for the top edge of the view.

See also:

Constant Value: 1 (0x00000001)

SOUND_EFFECTS_ENABLED

Added in API level 1
int SOUND_EFFECTS_ENABLED

View flag indicating whether this view should have sound effects enabled for events such as clicking and touching.

Constant Value: 134217728 (0x08000000)

STATUS_BAR_HIDDEN

Added in API level 11
int STATUS_BAR_HIDDEN

This constant was deprecated in API level 14.
Use SYSTEM_UI_FLAG_LOW_PROFILE instead.

Constant Value: 1 (0x00000001)

STATUS_BAR_VISIBLE

Added in API level 11
int STATUS_BAR_VISIBLE

This constant was deprecated in API level 14.
Use SYSTEM_UI_FLAG_VISIBLE instead.

Constant Value: 0 (0x00000000)

SYSTEM_UI_FLAG_FULLSCREEN

Added in API level 16
int SYSTEM_UI_FLAG_FULLSCREEN

Flag for setSystemUiVisibility(int): View has requested to go into the normal fullscreen mode so that its content can take over the screen while still allowing the user to interact with the application.

This has the same visual effect as WindowManager.LayoutParams.FLAG_FULLSCREEN, meaning that non-critical screen decorations (such as the status bar) will be hidden while the user is in the View's window, focusing the experience on that content. Unlike the window flag, if you are using ActionBar in overlay mode with Window.FEATURE_ACTION_BAR_OVERLAY, then enabling this flag will also hide the action bar.

This approach to going fullscreen is best used over the window flag when it is a transient state -- that is, the application does this at certain points in its user interaction where it wants to allow the user to focus on content, but not as a continuous state. For situations where the application would like to simply stay full screen the entire time (such as a game that wants to take over the screen), the window flag is usually a better approach. The state set here will be removed by the system in various situations (such as the user moving to another application) like the other system UI states.

When using this flag, the application should provide some easy facility for the user to go out of it. A common example would be in an e-book reader, where tapping on the screen brings back whatever screen and UI decorations that had been hidden while the user was immersed in reading the book.

See also:

Constant Value: 4 (0x00000004)

SYSTEM_UI_FLAG_HIDE_NAVIGATION

Added in API level 14
int SYSTEM_UI_FLAG_HIDE_NAVIGATION

Flag for setSystemUiVisibility(int): View has requested that the system navigation be temporarily hidden.

This is an even less obtrusive state than that called for by SYSTEM_UI_FLAG_LOW_PROFILE; on devices that draw essential navigation controls (Home, Back, and the like) on screen, SYSTEM_UI_FLAG_HIDE_NAVIGATION will cause those to disappear. This is useful (in conjunction with the FLAG_FULLSCREEN and FLAG_LAYOUT_IN_SCREEN window flags) for displaying content using every last pixel on the display.

There is a limitation: because navigation controls are so important, the least user interaction will cause them to reappear immediately. When this happens, both this flag and SYSTEM_UI_FLAG_FULLSCREEN will be cleared automatically, so that both elements reappear at the same time.

See also:

Constant Value: 2 (0x00000002)

SYSTEM_UI_FLAG_IMMERSIVE

Added in API level 19
int SYSTEM_UI_FLAG_IMMERSIVE

Flag for setSystemUiVisibility(int): View would like to remain interactive when hiding the navigation bar with SYSTEM_UI_FLAG_HIDE_NAVIGATION. If this flag is not set, SYSTEM_UI_FLAG_HIDE_NAVIGATION will be force cleared by the system on any user interaction.

Since this flag is a modifier for SYSTEM_UI_FLAG_HIDE_NAVIGATION, it only has an effect when used in combination with that flag.

Constant Value: 2048 (0x00000800)

SYSTEM_UI_FLAG_IMMERSIVE_STICKY

Added in API level 19
int SYSTEM_UI_FLAG_IMMERSIVE_STICKY

Flag for setSystemUiVisibility(int): View would like to remain interactive when hiding the status bar with SYSTEM_UI_FLAG_FULLSCREEN and/or hiding the navigation bar with SYSTEM_UI_FLAG_HIDE_NAVIGATION. Use this flag to create an immersive experience while also hiding the system bars. If this flag is not set, SYSTEM_UI_FLAG_HIDE_NAVIGATION will be force cleared by the system on any user interaction, and SYSTEM_UI_FLAG_FULLSCREEN will be force-cleared by the system if the user swipes from the top of the screen.

When system bars are hidden in immersive mode, they can be revealed temporarily with system gestures, such as swiping from the top of the screen. These transient system bars will overlay app’s content, may have some degree of transparency, and will automatically hide after a short timeout.

Since this flag is a modifier for SYSTEM_UI_FLAG_FULLSCREEN and SYSTEM_UI_FLAG_HIDE_NAVIGATION, it only has an effect when used in combination with one or both of those flags.

Constant Value: 4096 (0x00001000)

SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

Added in API level 16
int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

Flag for setSystemUiVisibility(int): View would like its window to be laid out as if it has requested SYSTEM_UI_FLAG_FULLSCREEN, even if it currently hasn't. This allows it to avoid artifacts when switching in and out of that mode, at the expense that some of its user interface may be covered by screen decorations when they are shown. You can perform layout of your inner UI elements to account for non-fullscreen system UI through the fitSystemWindows(Rect) method.

Constant Value: 1024 (0x00000400)

SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

Added in API level 16
int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

Flag for setSystemUiVisibility(int): View would like its window to be laid out as if it has requested SYSTEM_UI_FLAG_HIDE_NAVIGATION, even if it currently hasn't. This allows it to avoid artifacts when switching in and out of that mode, at the expense that some of its user interface may be covered by screen decorations when they are shown. You can perform layout of your inner UI elements to account for the navigation system UI through the fitSystemWindows(Rect) method.

Constant Value: 512 (0x00000200)

SYSTEM_UI_FLAG_LAYOUT_STABLE

Added in API level 16
int SYSTEM_UI_FLAG_LAYOUT_STABLE

Flag for setSystemUiVisibility(int): When using other layout flags, we would like a stable view of the content insets given to fitSystemWindows(Rect). This means that the insets seen there will always represent the worst case that the application can expect as a continuous state. In the stock Android UI this is the space for the system bar, nav bar, and status bar, but not more transient elements such as an input method. The stable layout your UI sees is based on the system UI modes you can switch to. That is, if you specify SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN then you will get a stable layout for changes of the SYSTEM_UI_FLAG_FULLSCREEN mode; if you specify SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN and SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION, then you can transition to SYSTEM_UI_FLAG_FULLSCREEN and SYSTEM_UI_FLAG_HIDE_NAVIGATION with a stable layout. (Note that you should avoid using SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION by itself.) If you have set the window flag FLAG_FULLSCREEN to hide the status bar (instead of using SYSTEM_UI_FLAG_FULLSCREEN), then a hidden status bar will be considered a "stable" state for purposes here. This allows your UI to continually hide the status bar, while still using the system UI flags to hide the action bar while still retaining a stable layout. Note that changing the window fullscreen flag will never provide a stable layout for a clean transition.

If you are using ActionBar in overlay mode with Window.FEATURE_ACTION_BAR_OVERLAY, this flag will also impact the insets it adds to those given to the application.

Constant Value: 256 (0x00000100)

SYSTEM_UI_FLAG_LIGHT_STATUS_BAR

Added in API level 23
int SYSTEM_UI_FLAG_LIGHT_STATUS_BAR

Flag for setSystemUiVisibility(int): Requests the status bar to draw in a mode that is compatible with light status bar backgrounds.

For this to take effect, the window must request FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS but not FLAG_TRANSLUCENT_STATUS.

See also:

Constant Value: 8192 (0x00002000)

SYSTEM_UI_FLAG_LOW_PROFILE

Added in API level 14
int SYSTEM_UI_FLAG_LOW_PROFILE

Flag for setSystemUiVisibility(int): View has requested the system UI to enter an unobtrusive "low profile" mode.

This is for use in games, book readers, video players, or any other "immersive" application where the usual system chrome is deemed too distracting.

In low profile mode, the status bar and/or navigation icons may dim.

See also:

Constant Value: 1 (0x00000001)

SYSTEM_UI_FLAG_VISIBLE

Added in API level 14
int SYSTEM_UI_FLAG_VISIBLE

Special constant for setSystemUiVisibility(int): View has requested the system UI (status bar) to be visible (the default).

See also:

Constant Value: 0 (0x00000000)

SYSTEM_UI_LAYOUT_FLAGS

Added in API level 16
int SYSTEM_UI_LAYOUT_FLAGS

Flags that can impact the layout in relation to system UI.

Constant Value: 1536 (0x00000600)

TEXT_ALIGNMENT_CENTER

Added in API level 17
int TEXT_ALIGNMENT_CENTER

Center the paragraph, e.g. ALIGN_CENTER. Use with setTextAlignment(int)

Constant Value: 4 (0x00000004)

TEXT_ALIGNMENT_GRAVITY

Added in API level 17
int TEXT_ALIGNMENT_GRAVITY

Default for the root view. The gravity determines the text alignment, ALIGN_NORMAL, ALIGN_CENTER, or ALIGN_OPPOSITE, which are relative to each paragraph’s text direction. Use with setTextAlignment(int)

Constant Value: 1 (0x00000001)

TEXT_ALIGNMENT_INHERIT

Added in API level 16
int TEXT_ALIGNMENT_INHERIT

Default text alignment. The text alignment of this View is inherited from its parent. Use with setTextAlignment(int)

Constant Value: 0 (0x00000000)

TEXT_ALIGNMENT_TEXT_END

Added in API level 17
int TEXT_ALIGNMENT_TEXT_END

Align to the end of the paragraph, e.g. ALIGN_OPPOSITE. Use with setTextAlignment(int)

Constant Value: 3 (0x00000003)

TEXT_ALIGNMENT_TEXT_START

Added in API level 17
int TEXT_ALIGNMENT_TEXT_START

Align to the start of the paragraph, e.g. ALIGN_NORMAL. Use with setTextAlignment(int)

Constant Value: 2 (0x00000002)

TEXT_ALIGNMENT_VIEW_END

Added in API level 17
int TEXT_ALIGNMENT_VIEW_END

Align to the end of the view, which is ALIGN_RIGHT if the view’s resolved layoutDirection is LTR, and ALIGN_LEFT otherwise. Use with setTextAlignment(int)

Constant Value: 6 (0x00000006)

TEXT_ALIGNMENT_VIEW_START

Added in API level 17
int TEXT_ALIGNMENT_VIEW_START

Align to the start of the view, which is ALIGN_LEFT if the view’s resolved layoutDirection is LTR, and ALIGN_RIGHT otherwise. Use with setTextAlignment(int)

Constant Value: 5 (0x00000005)

TEXT_DIRECTION_ANY_RTL

Added in API level 17
int TEXT_DIRECTION_ANY_RTL

Text direction is using "any-RTL" algorithm. The paragraph direction is RTL if it contains any strong RTL character, otherwise it is LTR if it contains any strong LTR characters. If there are neither, the paragraph direction is the view's resolved layout direction.

Constant Value: 2 (0x00000002)

TEXT_DIRECTION_FIRST_STRONG

Added in API level 17
int TEXT_DIRECTION_FIRST_STRONG

Text direction is using "first strong algorithm". The first strong directional character determines the paragraph direction. If there is no strong directional character, the paragraph direction is the view's resolved layout direction.

Constant Value: 1 (0x00000001)

TEXT_DIRECTION_FIRST_STRONG_LTR

Added in API level 23
int TEXT_DIRECTION_FIRST_STRONG_LTR

Text direction is using "first strong algorithm". The first strong directional character determines the paragraph direction. If there is no strong directional character, the paragraph direction is LTR.

Constant Value: 6 (0x00000006)

TEXT_DIRECTION_FIRST_STRONG_RTL

Added in API level 23
int TEXT_DIRECTION_FIRST_STRONG_RTL

Text direction is using "first strong algorithm". The first strong directional character determines the paragraph direction. If there is no strong directional character, the paragraph direction is RTL.

Constant Value: 7 (0x00000007)

TEXT_DIRECTION_INHERIT

Added in API level 17
int TEXT_DIRECTION_INHERIT

Text direction is inherited through ViewGroup

Constant Value: 0 (0x00000000)

TEXT_DIRECTION_LOCALE

Added in API level 17
int TEXT_DIRECTION_LOCALE

Text direction is coming from the system Locale.

Constant Value: 5 (0x00000005)

TEXT_DIRECTION_LTR

Added in API level 17
int TEXT_DIRECTION_LTR

Text direction is forced to LTR.

Constant Value: 3 (0x00000003)

TEXT_DIRECTION_RTL

Added in API level 17
int TEXT_DIRECTION_RTL

Text direction is forced to RTL.

Constant Value: 4 (0x00000004)

VIEW_LOG_TAG

Added in API level 1
String VIEW_LOG_TAG

The logging tag used by this class with android.util.Log.

Constant Value: "View"

VISIBLE

Added in API level 1
int VISIBLE

This view is visible. Use with setVisibility(int) and android:visibility.

Constant Value: 0 (0x00000000)

Fields

ALPHA

Added in API level 14
Property<ViewFloat> ALPHA

A Property wrapper around the alpha functionality handled by the setAlpha(float) and getAlpha() methods.

EMPTY_STATE_SET

Added in API level 1
int[] EMPTY_STATE_SET

Indicates the view has no states set. States are used with Drawable to change the drawing of the view depending on its state.

See also:

ENABLED_FOCUSED_SELECTED_STATE_SET

Added in API level 1
int[] ENABLED_FOCUSED_SELECTED_STATE_SET

Indicates the view is enabled, focused and selected.

See also:

ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Added in API level 1
int[] ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Indicates the view is enabled, focused, selected and its window has the focus.

See also:

ENABLED_FOCUSED_STATE_SET

Added in API level 1
int[] ENABLED_FOCUSED_STATE_SET

Indicates the view is enabled and has the focus.

See also:

ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET

Added in API level 1
int[] ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET

Indicates the view is enabled, focused and its window has the focus.

See also:

ENABLED_SELECTED_STATE_SET

Added in API level 1
int[] ENABLED_SELECTED_STATE_SET

Indicates the view is enabled and selected.

See also:

ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET

Added in API level 1
int[] ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET

Indicates the view is enabled, selected and its window has the focus.

See also:

ENABLED_STATE_SET

Added in API level 1
int[] ENABLED_STATE_SET

Indicates the view is enabled. States are used with Drawable to change the drawing of the view depending on its state.

See also:

ENABLED_WINDOW_FOCUSED_STATE_SET

Added in API level 1
int[] ENABLED_WINDOW_FOCUSED_STATE_SET

Indicates the view is enabled and that its window has focus.

See also:

FOCUSED_SELECTED_STATE_SET

Added in API level 1
int[] FOCUSED_SELECTED_STATE_SET

Indicates the view is focused and selected.

See also:

FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Added in API level 1
int[] FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Indicates the view is focused, selected and its window has the focus.

See also:

FOCUSED_STATE_SET

Added in API level 1
int[] FOCUSED_STATE_SET

Indicates the view is focused. States are used with Drawable to change the drawing of the view depending on its state.

See also:

FOCUSED_WINDOW_FOCUSED_STATE_SET

Added in API level 1
int[] FOCUSED_WINDOW_FOCUSED_STATE_SET

Indicates the view has the focus and that its window has the focus.

See also:

PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET

Added in API level 1
int[] PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET

Indicates the view is pressed, enabled, focused and selected.

See also:

PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Added in API level 1
int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Indicates the view is pressed, enabled, focused, selected and its window has the focus.

See also:

PRESSED_ENABLED_FOCUSED_STATE_SET

Added in API level 1
int[] PRESSED_ENABLED_FOCUSED_STATE_SET

Indicates the view is pressed, enabled and focused.

See also:

PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET

Added in API level 1
int[] PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET

Indicates the view is pressed, enabled, focused and its window has the focus.

See also:

PRESSED_ENABLED_SELECTED_STATE_SET

Added in API level 1
int[] PRESSED_ENABLED_SELECTED_STATE_SET

Indicates the view is pressed, enabled and selected.

See also:

PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET

Added in API level 1
int[] PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET

Indicates the view is pressed, enabled, selected and its window has the focus.

See also:

PRESSED_ENABLED_STATE_SET

Added in API level 1
int[] PRESSED_ENABLED_STATE_SET

Indicates the view is pressed and enabled.

See also:

PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET

Added in API level 1
int[] PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET

Indicates the view is pressed, enabled and its window has the focus.

See also:

PRESSED_FOCUSED_SELECTED_STATE_SET

Added in API level 1
int[] PRESSED_FOCUSED_SELECTED_STATE_SET

Indicates the view is pressed, focused and selected.

See also:

PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Added in API level 1
int[] PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Indicates the view is pressed, focused, selected and its window has the focus.

See also:

PRESSED_FOCUSED_STATE_SET

Added in API level 1
int[] PRESSED_FOCUSED_STATE_SET

Indicates the view is pressed and focused.

See also:

PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET

Added in API level 1
int[] PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET

Indicates the view is pressed, focused and its window has the focus.

See also:

PRESSED_SELECTED_STATE_SET

Added in API level 1
int[] PRESSED_SELECTED_STATE_SET

Indicates the view is pressed and selected.

See also:

PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Added in API level 1
int[] PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET

Indicates the view is pressed, selected and its window has the focus.

See also:

PRESSED_STATE_SET

Added in API level 19
int[] PRESSED_STATE_SET

Indicates the view is pressed. States are used with Drawable to change the drawing of the view depending on its state.

See also:

PRESSED_WINDOW_FOCUSED_STATE_SET

Added in API level 1
int[] PRESSED_WINDOW_FOCUSED_STATE_SET

Indicates the view is pressed and its window has the focus.

See also:

ROTATION

Added in API level 14
Property<ViewFloat> ROTATION

A Property wrapper around the rotation functionality handled by the setRotation(float) and getRotation() methods.

ROTATION_X

Added in API level 14
Property<ViewFloat> ROTATION_X

A Property wrapper around the rotationX functionality handled by the setRotationX(float) and getRotationX() methods.

ROTATION_Y

Added in API level 14
Property<ViewFloat> ROTATION_Y

A Property wrapper around the rotationY functionality handled by the setRotationY(float) and getRotationY() methods.

SCALE_X

Added in API level 14
Property<ViewFloat> SCALE_X

A Property wrapper around the scaleX functionality handled by the setScaleX(float) and getScaleX() methods.

SCALE_Y

Added in API level 14
Property<ViewFloat> SCALE_Y

A Property wrapper around the scaleY functionality handled by the setScaleY(float) and getScaleY() methods.

SELECTED_STATE_SET

Added in API level 1
int[] SELECTED_STATE_SET

Indicates the view is selected. States are used with Drawable to change the drawing of the view depending on its state.

See also:

SELECTED_WINDOW_FOCUSED_STATE_SET

Added in API level 1
int[] SELECTED_WINDOW_FOCUSED_STATE_SET

Indicates the view is selected and that its window has the focus.

See also:

TRANSLATION_X

Added in API level 14
Property<ViewFloat> TRANSLATION_X

A Property wrapper around the translationX functionality handled by the setTranslationX(float) and getTranslationX() methods.

TRANSLATION_Y

Added in API level 14
Property<ViewFloat> TRANSLATION_Y

A Property wrapper around the translationY functionality handled by the setTranslationY(float) and getTranslationY() methods.

TRANSLATION_Z

Added in API level 21
Property<ViewFloat> TRANSLATION_Z

A Property wrapper around the translationZ functionality handled by the setTranslationZ(float) and getTranslationZ() methods.

WINDOW_FOCUSED_STATE_SET

Added in API level 1
int[] WINDOW_FOCUSED_STATE_SET

Indicates the view's window has focus. States are used with Drawable to change the drawing of the view depending on its state.

See also:

X

Added in API level 14
Property<ViewFloat> X

A Property wrapper around the x functionality handled by the setX(float) and getX() methods.

Y

Added in API level 14
Property<ViewFloat> Y

A Property wrapper around the y functionality handled by the setY(float) and getY() methods.

Z

Added in API level 21
Property<ViewFloat> Z

A Property wrapper around the z functionality handled by the setZ(float) and getZ() methods.

Public constructors

View

Added in API level 1
View (Context context)

Simple constructor to use when creating a view from code.

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, etc.

View

Added in API level 1
View (Context context, 
                AttributeSet attrs)

Constructor that is called when inflating a view from XML. This is called when a view is being constructed from an XML file, supplying attributes that were specified in the XML file. This version uses a default style of 0, so the only attribute values applied are those in the Context's Theme and the given AttributeSet.

The method onFinishInflate() will be called after all children have been added.

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, etc.
attrs AttributeSet: The attributes of the XML tag that is inflating the view.

See also:

View

Added in API level 1
View (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Perform inflation from XML and apply a class-specific base style from a theme attribute. This constructor of View allows subclasses to use their own base style when they are inflating. For example, a Button class's constructor would call this version of the super class constructor and supply R.attr.buttonStyle for defStyleAttr; this allows the theme's button style to modify all of the base view attributes (in particular its background) as well as the Button class's attributes.

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, etc.
attrs AttributeSet: The attributes of the XML tag that is inflating the view.
defStyleAttr int: An attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be 0 to not look for defaults.

See also:

View

Added in API level 21
View (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Perform inflation from XML and apply a class-specific base style from a theme attribute or style resource. This constructor of View allows subclasses to use their own base style when they are inflating.

When determining the final value of a particular attribute, there are four inputs that come into play:

  1. Any attribute values in the given AttributeSet.
  2. The style resource specified in the AttributeSet (named "style").
  3. The default style specified by defStyleAttr.
  4. The default style specified by defStyleRes.
  5. The base values in this theme.

Each of these inputs is considered in-order, with the first listed taking precedence over the following ones. In other words, if in the AttributeSet you have supplied <Button * textColor="#ff000000"> , then the button's text will always be black, regardless of what is specified in any of the styles.

Parameters
context Context: The Context the view is running in, through which it can access the current theme, resources, etc.
attrs AttributeSet: The attributes of the XML tag that is inflating the view.
defStyleAttr int: An attribute in the current theme that contains a reference to a style resource that supplies default values for the view. Can be 0 to not look for defaults.
defStyleRes int: A resource identifier of a style resource that supplies default values for the view, used only if defStyleAttr is 0 or can not be found in the theme. Can be 0 to not look for defaults.

See also:

Public methods

addChildrenForAccessibility

Added in API level 16
void addChildrenForAccessibility (ArrayList<View> outChildren)

Adds the children of this View relevant for accessibility to the given list as output. Since some Views are not important for accessibility the added child views are not necessarily direct children of this view, rather they are the first level of descendants important for accessibility.

Parameters
outChildren ArrayList: The output list that will receive children for accessibility.

addFocusables

Added in API level 1
void addFocusables (ArrayList<View> views, 
                int direction)

Add any focusable views that are descendants of this view (possibly including this view if it is focusable itself) to views. If we are in touch mode, only add views that are also focusable in touch mode.

Parameters
views ArrayList: Focusable views found so far
direction int: The direction of the focus

addFocusables

Added in API level 4
void addFocusables (ArrayList<View> views, 
                int direction, 
                int focusableMode)

Adds any focusable views that are descendants of this view (possibly including this view if it is focusable itself) to views. This method adds all focusable views regardless if we are in touch mode or only views focusable in touch mode if we are in touch mode or only views that can take accessibility focus if accessibility is enabled depending on the focusable mode parameter.

Parameters
views ArrayList: Focusable views found so far or null if all we are interested is the number of focusables.
direction int: The direction of the focus.
focusableMode int: The type of focusables to be added.

See also:

addOnAttachStateChangeListener

Added in API level 12
void addOnAttachStateChangeListener (View.OnAttachStateChangeListener listener)

Add a listener for attach state changes. This listener will be called whenever this view is attached or detached from a window. Remove the listener using removeOnAttachStateChangeListener(OnAttachStateChangeListener).

Parameters
listener View.OnAttachStateChangeListener: Listener to attach

See also:

addOnLayoutChangeListener

Added in API level 11
void addOnLayoutChangeListener (View.OnLayoutChangeListener listener)

Add a listener that will be called when the bounds of the view change due to layout processing.

Parameters
listener View.OnLayoutChangeListener: The listener that will be called when layout bounds change.

addTouchables

Added in API level 1
void addTouchables (ArrayList<View> views)

Add any touchable views that are descendants of this view (possibly including this view if it is touchable itself) to views.

Parameters
views ArrayList: Touchable views found so far

animate

Added in API level 12
ViewPropertyAnimator animate ()

This method returns a ViewPropertyAnimator object, which can be used to animate specific properties on this View.

Returns
ViewPropertyAnimator ViewPropertyAnimator The ViewPropertyAnimator associated with this View.

announceForAccessibility

Added in API level 16
void announceForAccessibility (CharSequence text)

Convenience method for sending a TYPE_ANNOUNCEMENT AccessibilityEvent to make an announcement which is related to some sort of a context change for which none of the events representing UI transitions is a good fit. For example, announcing a new page in a book. If accessibility is not enabled this method does nothing.

Parameters
text CharSequence: The announcement text.

bringToFront

Added in API level 1
void bringToFront ()

Change the view's z order in the tree, so it's on top of other sibling views. This ordering change may affect layout, if the parent container uses an order-dependent layout scheme (e.g., LinearLayout). Prior to KITKAT this method should be followed by calls to requestLayout() and invalidate() on the view's parent to force the parent to redraw with the new child ordering.

See also:

buildDrawingCache

Added in API level 4
void buildDrawingCache (boolean autoScale)

Forces the drawing cache to be built if the drawing cache is invalid.

If you call buildDrawingCache() manually without calling setDrawingCacheEnabled(true), you should cleanup the cache by calling destroyDrawingCache() afterwards.

Note about auto scaling in compatibility mode: When auto scaling is not enabled, this method will create a bitmap of the same size as this view. Because this bitmap will be drawn scaled by the parent ViewGroup, the result on screen might show scaling artifacts. To avoid such artifacts, you should call this method by setting the auto scaling to true. Doing so, however, will generate a bitmap of a different size than the view. This implies that your application must be able to handle this size.

You should avoid calling this method when hardware acceleration is enabled. If you do not need the drawing cache bitmap, calling this method will increase memory usage and cause the view to be rendered in software once, thus negatively impacting performance.

Parameters
autoScale boolean

See also:

buildDrawingCache

Added in API level 1
void buildDrawingCache ()

Calling this method is equivalent to calling buildDrawingCache(false).

See also:

buildLayer

Added in API level 12
void buildLayer ()

Forces this view's layer to be created and this view to be rendered into its layer. If this view's layer type is set to LAYER_TYPE_NONE, invoking this method will have no effect. This method can for instance be used to render a view into its layer before starting an animation. If this view is complex, rendering into the layer before starting the animation will avoid skipping frames.

Throws
IllegalStateException If this view is not attached to a window

See also:

callOnClick

Added in API level 15
boolean callOnClick ()

Directly call any attached OnClickListener. Unlike performClick(), this only calls the listener, and does not do any associated clicking actions like reporting an accessibility event.

Returns
boolean True there was an assigned OnClickListener that was called, false otherwise is returned.

canResolveLayoutDirection

Added in API level 19
boolean canResolveLayoutDirection ()

Check if layout direction resolution can be done.

Returns
boolean true if layout direction resolution can be done otherwise return false.

canResolveTextAlignment

Added in API level 19
boolean canResolveTextAlignment ()

Check if text alignment resolution can be done.

Returns
boolean true if text alignment resolution can be done otherwise return false.

canResolveTextDirection

Added in API level 19
boolean canResolveTextDirection ()

Check if text direction resolution can be done.

Returns
boolean true if text direction resolution can be done otherwise return false.

canScrollHorizontally

Added in API level 14
boolean canScrollHorizontally (int direction)

Check if this view can be scrolled horizontally in a certain direction.

Parameters
direction int: Negative to check scrolling left, positive to check scrolling right.
Returns
boolean true if this view can be scrolled in the specified direction, false otherwise.

canScrollVertically

Added in API level 14
boolean canScrollVertically (int direction)

Check if this view can be scrolled vertically in a certain direction.

Parameters
direction int: Negative to check scrolling up, positive to check scrolling down.
Returns
boolean true if this view can be scrolled in the specified direction, false otherwise.

cancelDragAndDrop

Added in API level 24
void cancelDragAndDrop ()

Cancels an ongoing drag and drop operation.

A DragEvent object with getAction() value of ACTION_DRAG_ENDED and getResult() value of false will be sent to every View that received ACTION_DRAG_STARTED even if they are not currently visible.

This method can be called on any View in the same window as the View on which startDragAndDrop was called.

cancelLongPress

Added in API level 1
void cancelLongPress ()

Cancels a pending long press. Your subclass can use this if you want the context menu to come up if the user presses and holds at the same place, but you don't want it to come up if they press and then move around enough to cause scrolling.

cancelPendingInputEvents

Added in API level 19
void cancelPendingInputEvents ()

Cancel any deferred high-level input events that were previously posted to the event queue.

Many views post high-level events such as click handlers to the event queue to run deferred in order to preserve a desired user experience - clearing visible pressed states before executing, etc. This method will abort any events of this nature that are currently in flight.

Custom views that generate their own high-level deferred input events should override onCancelPendingInputEvents() and remove those pending events from the queue.

This will also cancel pending input events for any child views.

Note that this may not be sufficient as a debouncing strategy for clicks in all cases. This will not impact newer events posted after this call that may occur as a result of lower-level input events still waiting in the queue. If you are trying to prevent double-submitted events for the duration of some sort of asynchronous transaction you should also take other steps to protect against unexpected double inputs e.g. calling setEnabled(false) and re-enabling the view when the transaction completes, tracking already submitted transaction IDs, etc.

checkInputConnectionProxy

Added in API level 3
boolean checkInputConnectionProxy (View view)

Called by the InputMethodManager when a view who is not the current input connection target is trying to make a call on the manager. The default implementation returns false; you can override this to return true for certain views if you are performing InputConnection proxying to them.

Parameters
view View: The View that is making the InputMethodManager call.
Returns
boolean Return true to allow the call, false to reject.

clearAnimation

Added in API level 1
void clearAnimation ()

Cancels any animations for this view.

clearFocus

Added in API level 1
void clearFocus ()

Called when this view wants to give up focus. If focus is cleared onFocusChanged(boolean, int, android.graphics.Rect) is called.

Note: When a View clears focus the framework is trying to give focus to the first focusable View from the top. Hence, if this View is the first from the top that can take focus, then all callbacks related to clearing focus will be invoked after which the framework will give focus to this view.

combineMeasuredStates

Added in API level 11
int combineMeasuredStates (int curState, 
                int newState)

Merge two states as returned by getMeasuredState().

Parameters
curState int: The current state as returned from a view or the result of combining multiple views.
newState int: The new view state to combine.
Returns
int Returns a new integer reflecting the combination of the two states.

computeScroll

Added in API level 1
void computeScroll ()

Called by a parent to request that a child update its values for mScrollX and mScrollY if necessary. This will typically be done if the child is animating a scroll using a Scroller object.

computeSystemWindowInsets

Added in API level 21
WindowInsets computeSystemWindowInsets (WindowInsets in, 
                Rect outLocalInsets)

Compute insets that should be consumed by this view and the ones that should propagate to those under it.

Parameters
in WindowInsets: Insets currently being processed by this View, likely received as a parameter to onApplyWindowInsets(WindowInsets).
outLocalInsets Rect: A Rect that will receive the insets that should be consumed by this view
Returns
WindowInsets Insets that should be passed along to views under this one

createAccessibilityNodeInfo

Added in API level 14
AccessibilityNodeInfo createAccessibilityNodeInfo ()

Returns an AccessibilityNodeInfo representing this view from the point of view of an AccessibilityService. This method is responsible for obtaining an accessibility node info from a pool of reusable instances and calling onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) on this view to initialize the former.

Note: The client is responsible for recycling the obtained instance by calling recycle() to minimize object creation.

Returns
AccessibilityNodeInfo A populated AccessibilityNodeInfo.

See also:

createContextMenu

Added in API level 1
void createContextMenu (ContextMenu menu)

Show the context menu for this view. It is not safe to hold on to the menu after returning from this method. You should normally not overload this method. Overload onCreateContextMenu(ContextMenu) or define an View.OnCreateContextMenuListener to add items to the context menu.

Parameters
menu ContextMenu: The context menu to populate

destroyDrawingCache

Added in API level 1
void destroyDrawingCache ()

Frees the resources used by the drawing cache. If you call buildDrawingCache() manually without calling setDrawingCacheEnabled(true), you should cleanup the cache with this method afterwards.

See also:

dispatchApplyWindowInsets

Added in API level 20
WindowInsets dispatchApplyWindowInsets (WindowInsets insets)

Request to apply the given window insets to this view or another view in its subtree.

This method should be called by clients wishing to apply insets corresponding to areas obscured by window decorations or overlays. This can include the status and navigation bars, action bars, input methods and more. New inset categories may be added in the future. The method returns the insets provided minus any that were applied by this view or its children.

Clients wishing to provide custom behavior should override the onApplyWindowInsets(WindowInsets) method or alternatively provide a View.OnApplyWindowInsetsListener via the setOnApplyWindowInsetsListener method.

This method replaces the older fitSystemWindows method.

Parameters
insets WindowInsets: Insets to apply
Returns
WindowInsets The provided insets minus the insets that were consumed

dispatchConfigurationChanged

Added in API level 8
void dispatchConfigurationChanged (Configuration newConfig)

Dispatch a notification about a resource configuration change down the view hierarchy. ViewGroups should override to route to their children.

Parameters
newConfig Configuration: The new resource configuration.

See also:

dispatchDisplayHint

Added in API level 8
void dispatchDisplayHint (int hint)

Dispatch a hint about whether this view is displayed. For instance, when a View moves out of the screen, it might receives a display hint indicating the view is not displayed. Applications should not rely on this hint as there is no guarantee that they will receive one.

Parameters
hint int: A hint about whether or not this view is displayed: VISIBLE or INVISIBLE.

dispatchDragEvent

Added in API level 11
boolean dispatchDragEvent (DragEvent event)

Detects if this View is enabled and has a drag event listener. If both are true, then it calls the drag event listener with the DragEvent it received. If the drag event listener returns true, then dispatchDragEvent() returns true.

For all other cases, the method calls the onDragEvent() drag event handler method and returns its result.

This ensures that a drag event is always consumed, even if the View does not have a drag event listener. However, if the View has a listener and the listener returns true, then onDragEvent() is not called.

Parameters
event DragEvent
Returns
boolean

dispatchDrawableHotspotChanged

Added in API level 22
void dispatchDrawableHotspotChanged (float x, 
                float y)

Dispatches drawableHotspotChanged to all of this View's children.

Parameters
x float: hotspot x coordinate
y float: hotspot y coordinate

See also:

dispatchFinishTemporaryDetach

Added in API level 24
void dispatchFinishTemporaryDetach ()

Dispatch onFinishTemporaryDetach() to this View and its direct children if this is a container View.

dispatchGenericMotionEvent

Added in API level 12
boolean dispatchGenericMotionEvent (MotionEvent event)

Dispatch a generic motion event.

Generic motion events with source class SOURCE_CLASS_POINTER are delivered to the view under the pointer. All other generic motion events are delivered to the focused view. Hover events are handled specially and are delivered to onHoverEvent(MotionEvent).

Parameters
event MotionEvent: The motion event to be dispatched.
Returns
boolean True if the event was handled by the view, false otherwise.

dispatchKeyEvent

Added in API level 1
boolean dispatchKeyEvent (KeyEvent event)

Dispatch a key event to the next view on the focus path. This path runs from the top of the view tree down to the currently focused view. If this view has focus, it will dispatch to itself. Otherwise it will dispatch the next node down the focus path. This method also fires any key listeners.

Parameters
event KeyEvent: The key event to be dispatched.
Returns
boolean True if the event was handled, false otherwise.

dispatchKeyEventPreIme

Added in API level 3
boolean dispatchKeyEventPreIme (KeyEvent event)

Dispatch a key event before it is processed by any input method associated with the view hierarchy. This can be used to intercept key events in special situations before the IME consumes them; a typical example would be handling the BACK key to update the application's UI instead of allowing the IME to see it and close itself.

Parameters
event KeyEvent: The key event to be dispatched.
Returns
boolean True if the event was handled, false otherwise.

dispatchKeyShortcutEvent

Added in API level 1
boolean dispatchKeyShortcutEvent (KeyEvent event)

Dispatches a key shortcut event.

Parameters
event KeyEvent: The key event to be dispatched.
Returns
boolean True if the event was handled by the view, false otherwise.

dispatchNestedFling

Added in API level 21
boolean dispatchNestedFling (float velocityX, 
                float velocityY, 
                boolean consumed)

Dispatch a fling to a nested scrolling parent.

This method should be used to indicate that a nested scrolling child has detected suitable conditions for a fling. Generally this means that a touch scroll has ended with a velocity in the direction of scrolling that meets or exceeds the minimum fling velocity along a scrollable axis.

If a nested scrolling child view would normally fling but it is at the edge of its own content, it can use this method to delegate the fling to its nested scrolling parent instead. The parent may optionally consume the fling or observe a child fling.

Parameters
velocityX float: Horizontal fling velocity in pixels per second
velocityY float: Vertical fling velocity in pixels per second
consumed boolean: true if the child consumed the fling, false otherwise
Returns
boolean true if the nested scrolling parent consumed or otherwise reacted to the fling

dispatchNestedPreFling

Added in API level 21
boolean dispatchNestedPreFling (float velocityX, 
                float velocityY)

Dispatch a fling to a nested scrolling parent before it is processed by this view.

Nested pre-fling events are to nested fling events what touch intercept is to touch and what nested pre-scroll is to nested scroll. dispatchNestedPreFling offsets an opportunity for the parent view in a nested fling to fully consume the fling before the child view consumes it. If this method returns true, a nested parent view consumed the fling and this view should not scroll as a result.

For a better user experience, only one view in a nested scrolling chain should consume the fling at a time. If a parent view consumed the fling this method will return false. Custom view implementations should account for this in two ways:

  • If a custom view is paged and needs to settle to a fixed page-point, do not call dispatchNestedPreFling; consume the fling and settle to a valid position regardless.
  • If a nested parent does consume the fling, this view should not scroll at all, even to settle back to a valid idle position.

Views should also not offer fling velocities to nested parent views along an axis where scrolling is not currently supported; a ScrollView should not offer a horizontal fling velocity to its parents since scrolling along that axis is not permitted and carrying velocity along that motion does not make sense.

Parameters
velocityX float: Horizontal fling velocity in pixels per second
velocityY float: Vertical fling velocity in pixels per second
Returns
boolean true if a nested scrolling parent consumed the fling

dispatchNestedPrePerformAccessibilityAction

Added in API level 22
boolean dispatchNestedPrePerformAccessibilityAction (int action, 
                Bundle arguments)

Report an accessibility action to this view's parents for delegated processing.

Implementations of performAccessibilityAction(int, Bundle) may internally call this method to delegate an accessibility action to a supporting parent. If the parent returns true from its onNestedPrePerformAccessibilityAction(View, int, android.os.Bundle) method this method will return true to signify that the action was consumed.

This method is useful for implementing nested scrolling child views. If isNestedScrollingEnabled() returns true and the action is a scrolling action a custom view implementation may invoke this method to allow a parent to consume the scroll first. If this method returns true the custom view should skip its own scrolling behavior.

Parameters
action int: Accessibility action to delegate
arguments Bundle: Optional action arguments
Returns
boolean true if the action was consumed by a parent

dispatchNestedPreScroll

Added in API level 21
boolean dispatchNestedPreScroll (int dx, 
                int dy, 
                int[] consumed, 
                int[] offsetInWindow)

Dispatch one step of a nested scroll in progress before this view consumes any portion of it.

Nested pre-scroll events are to nested scroll events what touch intercept is to touch. dispatchNestedPreScroll offers an opportunity for the parent view in a nested scrolling operation to consume some or all of the scroll operation before the child view consumes it.

Parameters
dx int: Horizontal scroll distance in pixels
dy int: Vertical scroll distance in pixels
consumed int: Output. If not null, consumed[0] will contain the consumed component of dx and consumed[1] the consumed dy.
offsetInWindow int: Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking.
Returns
boolean true if the parent consumed some or all of the scroll delta

See also:

dispatchNestedScroll

Added in API level 21
boolean dispatchNestedScroll (int dxConsumed, 
                int dyConsumed, 
                int dxUnconsumed, 
                int dyUnconsumed, 
                int[] offsetInWindow)

Dispatch one step of a nested scroll in progress.

Implementations of views that support nested scrolling should call this to report info about a scroll in progress to the current nested scrolling parent. If a nested scroll is not currently in progress or nested scrolling is not enabled for this view this method does nothing.

Compatible View implementations should also call dispatchNestedPreScroll before consuming a component of the scroll event themselves.

Parameters
dxConsumed int: Horizontal distance in pixels consumed by this view during this scroll step
dyConsumed int: Vertical distance in pixels consumed by this view during this scroll step
dxUnconsumed int: Horizontal scroll distance in pixels not consumed by this view
dyUnconsumed int: Horizontal scroll distance in pixels not consumed by this view
offsetInWindow int: Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking.
Returns
boolean true if the event was dispatched, false if it could not be dispatched.

See also:

dispatchPopulateAccessibilityEvent

Added in API level 4
boolean dispatchPopulateAccessibilityEvent (AccessibilityEvent event)

Dispatches an AccessibilityEvent to the View first and then to its children for adding their text content to the event. Note that the event text is populated in a separate dispatch path since we add to the event not only the text of the source but also the text of all its descendants. A typical implementation will call onPopulateAccessibilityEvent(AccessibilityEvent) on the this view and then call the dispatchPopulateAccessibilityEvent(AccessibilityEvent) on each child. Override this method if custom population of the event text content is required.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its dispatchPopulateAccessibilityEvent(View, AccessibilityEvent) is responsible for handling this call.

Note: Accessibility events of certain types are not dispatched for populating the event text via this method. For details refer to AccessibilityEvent.

Parameters
event AccessibilityEvent: The event.
Returns
boolean True if the event population was completed.

dispatchProvideStructure

Added in API level 23
void dispatchProvideStructure (ViewStructure structure)

Dispatch creation of ViewStructure down the hierarchy. The default implementation calls onProvideStructure(ViewStructure) and onProvideVirtualStructure(ViewStructure).

Parameters
structure ViewStructure

dispatchStartTemporaryDetach

Added in API level 24
void dispatchStartTemporaryDetach ()

Dispatch onStartTemporaryDetach() to this View and its direct children if this is a container View.

dispatchSystemUiVisibilityChanged

Added in API level 11
void dispatchSystemUiVisibilityChanged (int visibility)

Dispatch callbacks to setOnSystemUiVisibilityChangeListener(View.OnSystemUiVisibilityChangeListener) down the view hierarchy.

Parameters
visibility int

dispatchTouchEvent

Added in API level 1
boolean dispatchTouchEvent (MotionEvent event)

Pass the touch screen motion event down to the target view, or this view if it is the target.

Parameters
event MotionEvent: The motion event to be dispatched.
Returns
boolean True if the event was handled by the view, false otherwise.

dispatchTrackballEvent

Added in API level 1
boolean dispatchTrackballEvent (MotionEvent event)

Pass a trackball motion event down to the focused view.

Parameters
event MotionEvent: The motion event to be dispatched.
Returns
boolean True if the event was handled by the view, false otherwise.

dispatchUnhandledMove

Added in API level 1
boolean dispatchUnhandledMove (View focused, 
                int direction)

This method is the last chance for the focused view and its ancestors to respond to an arrow key. This is called when the focused view did not consume the key internally, nor could the view system find a new view in the requested direction to give focus to.

Parameters
focused View: The currently focused view.
direction int: The direction focus wants to move. One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT.
Returns
boolean True if the this view consumed this unhandled move.

dispatchWindowFocusChanged

Added in API level 1
void dispatchWindowFocusChanged (boolean hasFocus)

Called when the window containing this view gains or loses window focus. ViewGroups should override to route to their children.

Parameters
hasFocus boolean: True if the window containing this view now has focus, false otherwise.

dispatchWindowSystemUiVisiblityChanged

Added in API level 16
void dispatchWindowSystemUiVisiblityChanged (int visible)

Dispatch callbacks to onWindowSystemUiVisibilityChanged(int) down the view hierarchy.

Parameters
visible int

dispatchWindowVisibilityChanged

Added in API level 1
void dispatchWindowVisibilityChanged (int visibility)

Dispatch a window visibility change down the view hierarchy. ViewGroups should override to route to their children.

Parameters
visibility int: The new visibility of the window.

See also:

draw

Added in API level 1
void draw (Canvas canvas)

Manually render this view (and all of its children) to the given Canvas. The view must have already done a full layout before this function is called. When implementing a view, implement onDraw(android.graphics.Canvas) instead of overriding this method. If you do need to override this method, call the superclass version.

Parameters
canvas Canvas: The Canvas to which the View is rendered.

drawableHotspotChanged

Added in API level 21
void drawableHotspotChanged (float x, 
                float y)

This function is called whenever the view hotspot changes and needs to be propagated to drawables or child views managed by the view.

Dispatching to child views is handled by dispatchDrawableHotspotChanged(float, float).

Be sure to call through to the superclass when overriding this function.

Parameters
x float: hotspot x coordinate
y float: hotspot y coordinate

findFocus

Added in API level 1
View findFocus ()

Find the view in the hierarchy rooted at this view that currently has focus.

Returns
View The view that currently has focus, or null if no focused view can be found.

findViewById

Added in API level 1
View findViewById (int id)

Look for a child view with the given id. If this view has the given id, return this view.

Parameters
id int: The id to search for.
Returns
View The view that has the given id in the hierarchy or null

findViewWithTag

Added in API level 1
View findViewWithTag (Object tag)

Look for a child view with the given tag. If this view has the given tag, return this view.

Parameters
tag Object: The tag to search for, using "tag.equals(getTag())".
Returns
View The View that has the given tag in the hierarchy or null

findViewsWithText

Added in API level 14
void findViewsWithText (ArrayList<View> outViews, 
                CharSequence searched, 
                int flags)

Finds the Views that contain given text. The containment is case insensitive. The search is performed by either the text that the View renders or the content description that describes the view for accessibility purposes and the view does not render or both. Clients can specify how the search is to be performed via passing the FIND_VIEWS_WITH_TEXT and FIND_VIEWS_WITH_CONTENT_DESCRIPTION flags.

Parameters
outViews ArrayList: The output list of matching Views.
searched CharSequence: The text to match against.
flags int

See also:

focusSearch

Added in API level 1
View focusSearch (int direction)

Find the nearest view in the specified direction that can take focus. This does not actually give focus to that view.

Parameters
direction int: One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT
Returns
View The nearest focusable in the specified direction, or null if none can be found.

forceHasOverlappingRendering

Added in API level 24
void forceHasOverlappingRendering (boolean hasOverlappingRendering)

Sets the behavior for overlapping rendering for this view (see hasOverlappingRendering() for more details on this behavior). Calling this method is an alternative to overriding hasOverlappingRendering() in a subclass, providing the value which is then used internally. That is, when forceHasOverlappingRendering(boolean) is called, the value of hasOverlappingRendering() is ignored and the value passed into this method is used instead.

Related XML Attributes:

Parameters
hasOverlappingRendering boolean: The value for overlapping rendering to be used internally instead of that returned by hasOverlappingRendering().

forceLayout

Added in API level 1
void forceLayout ()

Forces this view to be laid out during the next layout pass. This method does not call requestLayout() or forceLayout() on the parent.

generateViewId

Added in API level 17
int generateViewId ()

Generate a value suitable for use in setId(int). This value will not collide with ID values generated at build time by aapt for R.id.

Returns
int a generated ID value

getAccessibilityClassName

Added in API level 23
CharSequence getAccessibilityClassName ()

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.

Returns
CharSequence

getAccessibilityLiveRegion

Added in API level 19
int getAccessibilityLiveRegion ()

Gets the live region mode for this View.

Related XML Attributes:

Returns
int The live region mode for the view.

See also:

getAccessibilityNodeProvider

Added in API level 16
AccessibilityNodeProvider getAccessibilityNodeProvider ()

Gets the provider for managing a virtual view hierarchy rooted at this View and reported to AccessibilityServices that explore the window content.

If this method returns an instance, this instance is responsible for managing AccessibilityNodeInfos describing the virtual sub-tree rooted at this View including the one representing the View itself. Similarly the returned instance is responsible for performing accessibility actions on any virtual view or the root view itself.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its getAccessibilityNodeProvider(View) is responsible for handling this call.

Returns
AccessibilityNodeProvider The provider.

See also:

getAccessibilityTraversalAfter

Added in API level 22
int getAccessibilityTraversalAfter ()

Gets the id of a view after which this one is visited in accessibility traversal.

Returns
int The id of a view this one succeedes in accessibility traversal if specified, otherwise NO_ID.

See also:

getAccessibilityTraversalBefore

Added in API level 22
int getAccessibilityTraversalBefore ()

Gets the id of a view before which this one is visited in accessibility traversal.

Returns
int The id of a view this one precedes in accessibility traversal if specified, otherwise NO_ID.

See also:

getAlpha

Added in API level 11
float getAlpha ()

The opacity of the view. This is a value from 0 to 1, where 0 means the view is completely transparent and 1 means the view is completely opaque.

By default this is 1.0f.

Returns
float The opacity of the view.

getAnimation

Added in API level 1
Animation getAnimation ()

Get the animation currently associated with this view.

Returns
Animation The animation that is currently playing or scheduled to play for this view.

getApplicationWindowToken

Added in API level 1
IBinder getApplicationWindowToken ()

Retrieve a unique token identifying the top-level "real" window of the window that this view is attached to. That is, this is like getWindowToken(), except if the window this view in is a panel window (attached to another containing window), then the token of the containing window is returned instead.

Returns
IBinder Returns the associated window token, either getWindowToken() or the containing window's token.

getBackground

Added in API level 1
Drawable getBackground ()

Gets the background drawable

Related XML Attributes:

Returns
Drawable The drawable used as the background for this view, if any.

See also:

getBackgroundTintList

Added in API level 21
ColorStateList getBackgroundTintList ()

Return the tint applied to the background drawable, if specified.

Related XML Attributes:

Returns
ColorStateList the tint applied to the background drawable

See also:

getBackgroundTintMode

Added in API level 21
PorterDuff.Mode getBackgroundTintMode ()

Return the blending mode used to apply the tint to the background drawable, if specified.

Related XML Attributes:

Returns
PorterDuff.Mode the blending mode used to apply the tint to the background drawable

See also:

getBaseline

Added in API level 1
int getBaseline ()

Return the offset of the widget's text baseline from the widget's top boundary. If this widget does not support baseline alignment, this method returns -1.

Returns
int the offset of the baseline within the widget's bounds or -1 if baseline alignment is not supported

getBottom

Added in API level 1
int getBottom ()

Bottom position of this view relative to its parent.

Returns
int The bottom of this view, in pixels.

getCameraDistance

Added in API level 16
float getCameraDistance ()

Gets the distance along the Z axis from the camera to this view.

Returns
float The distance along the Z axis.

See also:

getClipBounds

Added in API level 23
boolean getClipBounds (Rect outRect)

Populates an output rectangle with the clip bounds of the view, returning true if successful or false if the view's clip bounds are null.

Parameters
outRect Rect: rectangle in which to place the clip bounds of the view
Returns
boolean true if successful or false if the view's clip bounds are null

getClipBounds

Added in API level 18
Rect getClipBounds ()

Returns a copy of the current clipBounds.

Returns
Rect A copy of the current clip bounds if clip bounds are set, otherwise null.

getClipToOutline

Added in API level 21
boolean getClipToOutline ()

Returns whether the Outline should be used to clip the contents of the View.

Note that this flag will only be respected if the View's Outline returns true from canClip().

Returns
boolean

See also:

getContentDescription

Added in API level 4
CharSequence getContentDescription ()

Returns the View's content description.

Note: Do not override this method, as it will have no effect on the content description presented to accessibility services. You must call setContentDescription(CharSequence) to modify the content description.

Related XML Attributes:

Returns
CharSequence the content description

See also:

getContext

Added in API level 1
Context getContext ()

Returns the context the view is running in, through which it can access the current theme, resources, etc.

Returns
Context The view's Context.

getDefaultSize

Added in API level 1
int getDefaultSize (int size, 
                int measureSpec)

Utility to return a default size. Uses the supplied size if the MeasureSpec imposed no constraints. Will get larger if allowed by the MeasureSpec.

Parameters
size int: Default size for this view
measureSpec int: Constraints imposed by the parent
Returns
int The size this view should be.

getDisplay

Added in API level 17
Display getDisplay ()

Gets the logical display to which the view's window has been attached.

Returns
Display The logical display, or null if the view is not currently attached to a window.

getDrawableState

Added in API level 1
int[] getDrawableState ()

Return an array of resource IDs of the drawable states representing the current state of the view.

Returns
int[] The current drawable state

See also:

getDrawingCache

Added in API level 1
Bitmap getDrawingCache ()

Calling this method is equivalent to calling getDrawingCache(false).

Returns
Bitmap A non-scaled bitmap representing this view or null if cache is disabled.

See also:

getDrawingCache

Added in API level 4
Bitmap getDrawingCache (boolean autoScale)

Returns the bitmap in which this view drawing is cached. The returned bitmap is null when caching is disabled. If caching is enabled and the cache is not ready, this method will create it. Calling draw(android.graphics.Canvas) will not draw from the cache when the cache is enabled. To benefit from the cache, you must request the drawing cache by calling this method and draw it on screen if the returned bitmap is not null.

Note about auto scaling in compatibility mode: When auto scaling is not enabled, this method will create a bitmap of the same size as this view. Because this bitmap will be drawn scaled by the parent ViewGroup, the result on screen might show scaling artifacts. To avoid such artifacts, you should call this method by setting the auto scaling to true. Doing so, however, will generate a bitmap of a different size than the view. This implies that your application must be able to handle this size.

Parameters
autoScale boolean: Indicates whether the generated bitmap should be scaled based on the current density of the screen when the application is in compatibility mode.
Returns
Bitmap A bitmap representing this view or null if cache is disabled.

See also:

getDrawingCacheBackgroundColor

Added in API level 1
int getDrawingCacheBackgroundColor ()

Returns
int The background color to used for the drawing cache's bitmap

See also:

getDrawingCacheQuality

Added in API level 1
int getDrawingCacheQuality ()

Returns the quality of the drawing cache.

Related XML Attributes:

Returns
int One of DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_LOW, or DRAWING_CACHE_QUALITY_HIGH

See also:

getDrawingRect

Added in API level 1
void getDrawingRect (Rect outRect)

Return the visible drawing bounds of your view. Fills in the output rectangle with the values from getScrollX(), getScrollY(), getWidth(), and getHeight(). These bounds do not account for any transformation properties currently set on the view, such as setScaleX(float) or setRotation(float).

Parameters
outRect Rect: The (scrolled) drawing bounds of the view.

getDrawingTime

Added in API level 1
long getDrawingTime ()

Return the time at which the drawing of the view hierarchy started.

Returns
long the drawing start time in milliseconds

getElevation

Added in API level 21
float getElevation ()

The base elevation of this view relative to its parent, in pixels.

Returns
float The base depth position of the view, in pixels.

getFilterTouchesWhenObscured

Added in API level 9
boolean getFilterTouchesWhenObscured ()

Gets whether the framework should discard touches when the view's window is obscured by another visible window. Refer to the View security documentation for more details.

Related XML Attributes:

Returns
boolean True if touch filtering is enabled.

See also:

getFitsSystemWindows

Added in API level 16
boolean getFitsSystemWindows ()

Check for state of setFitsSystemWindows(boolean). If this method returns true, the default implementation of fitSystemWindows(Rect) will be executed.

Related XML Attributes:

Returns
boolean true if the default implementation of fitSystemWindows(Rect) will be executed.

See also:

getFocusables

Added in API level 1
ArrayList<View> getFocusables (int direction)

Find and return all focusable views that are descendants of this view, possibly including this view if it is focusable itself.

Parameters
direction int: The direction of the focus
Returns
ArrayList<View> A list of focusable views

getFocusedRect

Added in API level 1
void getFocusedRect (Rect r)

When a view has focus and the user navigates away from it, the next view is searched for starting from the rectangle filled in by this method. By default, the rectangle is the getDrawingRect(android.graphics.Rect)) of the view. However, if your view maintains some idea of internal selection, such as a cursor, or a selected row or column, you should override this method and fill in a more specific rectangle.

Parameters
r Rect: The rectangle to fill in, in this view's coordinates.

getForeground

Added in API level 1
Drawable getForeground ()

Returns the drawable used as the foreground of this View. The foreground drawable, if non-null, is always drawn on top of the view's content.

Returns
Drawable a Drawable or null if no foreground was set

See also:

getForegroundGravity

Added in API level 16
int getForegroundGravity ()

Describes how the foreground is positioned.

Related XML Attributes:

Returns
int foreground gravity.

See also:

getForegroundTintList

Added in API level 21
ColorStateList getForegroundTintList ()

Return the tint applied to the foreground drawable, if specified.

Related XML Attributes:

Returns
ColorStateList the tint applied to the foreground drawable

See also:

getForegroundTintMode

Added in API level 21
PorterDuff.Mode getForegroundTintMode ()

Return the blending mode used to apply the tint to the foreground drawable, if specified.

Related XML Attributes:

Returns
PorterDuff.Mode the blending mode used to apply the tint to the foreground drawable

See also:

getGlobalVisibleRect

Added in API level 1
boolean getGlobalVisibleRect (Rect r)

Parameters
r Rect
Returns
boolean

getGlobalVisibleRect

Added in API level 1
boolean getGlobalVisibleRect (Rect r, 
                Point globalOffset)

If some part of this view is not clipped by any of its parents, then return that area in r in global (root) coordinates. To convert r to local coordinates (without taking possible View rotations into account), offset it by -globalOffset (e.g. r.offset(-globalOffset.x, -globalOffset.y)). If the view is completely clipped or translated out, return false.

Parameters
r Rect: If true is returned, r holds the global coordinates of the visible portion of this view.
globalOffset Point: If true is returned, globalOffset holds the dx,dy between this view and its root. globalOffet may be null.
Returns
boolean true if r is non-empty (i.e. part of the view is visible at the root level.

getHandler

Added in API level 1
Handler getHandler ()

Returns
Handler A handler associated with the thread running the View. This handler can be used to pump events in the UI events queue.

getHasOverlappingRendering

Added in API level 24
boolean getHasOverlappingRendering ()

Returns the value for overlapping rendering that is used internally. This is either the value passed into forceHasOverlappingRendering(boolean), if called, or the return value of hasOverlappingRendering(), otherwise.

Returns
boolean The value for overlapping rendering being used internally.

getHeight

Added in API level 1
int getHeight ()

Return the height of your view.

Returns
int The height of your view, in pixels.

getHitRect

Added in API level 1
void getHitRect (Rect outRect)

Hit rectangle in parent's coordinates

Parameters
outRect Rect: The hit rectangle of the view.

getHorizontalFadingEdgeLength

Added in API level 1
int getHorizontalFadingEdgeLength ()

Returns the size of the horizontal faded edges used to indicate that more content in this view is visible.

Related XML Attributes:

Returns
int The size in pixels of the horizontal faded edge or 0 if horizontal faded edges are not enabled for this view.

getId

Added in API level 1
int getId ()

Returns this view's identifier.

Related XML Attributes:

Returns
int a positive integer used to identify the view or NO_ID if the view has no ID

See also:

getImportantForAccessibility

Added in API level 16
int getImportantForAccessibility ()

Gets the mode for determining whether this View is important for accessibility which is if it fires accessibility events and if it is reported to accessibility services that query the screen.

Related XML Attributes:

Returns
int The mode for determining whether a View is important for accessibility.

See also:

getKeepScreenOn

Added in API level 1
boolean getKeepScreenOn ()

Returns whether the screen should remain on, corresponding to the current value of KEEP_SCREEN_ON.

Related XML Attributes:

Returns
boolean Returns true if KEEP_SCREEN_ON is set.

See also:

getKeyDispatcherState

Added in API level 5
KeyEvent.DispatcherState getKeyDispatcherState ()

Return the global KeyEvent.DispatcherState for this view's window. Returns null if the view is not currently attached to the window. Normally you will not need to use this directly, but just use the standard high-level event callbacks like onKeyDown(int, KeyEvent).

Returns
KeyEvent.DispatcherState

getLabelFor

Added in API level 17
int getLabelFor ()

Gets the id of a view for which this view serves as a label for accessibility purposes.

Returns
int The labeled view id.

getLayerType

Added in API level 11
int getLayerType ()

Indicates what type of layer is currently associated with this view. By default a view does not have a layer, and the layer type is LAYER_TYPE_NONE. Refer to the documentation of setLayerType(int, android.graphics.Paint) for more information on the different types of layers.

Returns
int LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE

See also:

getLayoutDirection

Added in API level 17
int getLayoutDirection ()

Returns the resolved layout direction for this view.

Related XML Attributes:

Returns
int LAYOUT_DIRECTION_RTL if the layout direction is RTL or returns LAYOUT_DIRECTION_LTR if the layout direction is not RTL. For compatibility, this will return LAYOUT_DIRECTION_LTR if API version is lower than JELLY_BEAN_MR1.

getLayoutParams

Added in API level 1
ViewGroup.LayoutParams getLayoutParams ()

Get the LayoutParams associated with this view. All views should have layout parameters. These supply parameters to the parent of this view specifying how it should be arranged. There are many subclasses of ViewGroup.LayoutParams, and these correspond to the different subclasses of ViewGroup that are responsible for arranging their children. This method may return null if this View is not attached to a parent ViewGroup or setLayoutParams(android.view.ViewGroup.LayoutParams) was not invoked successfully. When a View is attached to a parent ViewGroup, this method must not return null.

Returns
ViewGroup.LayoutParams The LayoutParams associated with this view, or null if no parameters have been set yet

getLeft

Added in API level 1
int getLeft ()

Left position of this view relative to its parent.

Returns
int The left edge of this view, in pixels.

getLocalVisibleRect

Added in API level 1
boolean getLocalVisibleRect (Rect r)

Parameters
r Rect
Returns
boolean

getLocationInWindow

Added in API level 1
void getLocationInWindow (int[] outLocation)

Computes the coordinates of this view in its window. The argument must be an array of two integers. After the method returns, the array contains the x and y location in that order.

Parameters
outLocation int: an array of two integers in which to hold the coordinates

getLocationOnScreen

Added in API level 1
void getLocationOnScreen (int[] outLocation)

Computes the coordinates of this view on the screen. The argument must be an array of two integers. After the method returns, the array contains the x and y location in that order.

Parameters
outLocation int: an array of two integers in which to hold the coordinates

getMatrix

Added in API level 11
Matrix getMatrix ()

The transform matrix of this view, which is calculated based on the current rotation, scale, and pivot properties.

Returns
Matrix The current transform matrix for the view

See also:

getMeasuredHeight

Added in API level 1
int getMeasuredHeight ()

Like getMeasuredHeightAndState(), but only returns the raw width component (that is the result is masked by MEASURED_SIZE_MASK).

Returns
int The raw measured height of this view.

getMeasuredHeightAndState

Added in API level 11
int getMeasuredHeightAndState ()

Return the full height measurement information for this view as computed by the most recent call to measure(int, int). This result is a bit mask as defined by MEASURED_SIZE_MASK and MEASURED_STATE_TOO_SMALL. This should be used during measurement and layout calculations only. Use getHeight() to see how wide a view is after layout.

Returns
int The measured width of this view as a bit mask.

getMeasuredState

Added in API level 11
int getMeasuredState ()

Return only the state bits of getMeasuredWidthAndState() and getMeasuredHeightAndState(), combined into one integer. The width component is in the regular bits MEASURED_STATE_MASK and the height component is at the shifted bits MEASURED_HEIGHT_STATE_SHIFT>>MEASURED_STATE_MASK.

Returns
int

getMeasuredWidth

Added in API level 1
int getMeasuredWidth ()

Like getMeasuredWidthAndState(), but only returns the raw width component (that is the result is masked by MEASURED_SIZE_MASK).

Returns
int The raw measured width of this view.

getMeasuredWidthAndState

Added in API level 11
int getMeasuredWidthAndState ()

Return the full width measurement information for this view as computed by the most recent call to measure(int, int). This result is a bit mask as defined by MEASURED_SIZE_MASK and MEASURED_STATE_TOO_SMALL. This should be used during measurement and layout calculations only. Use getWidth() to see how wide a view is after layout.

Returns
int The measured width of this view as a bit mask.

getMinimumHeight

Added in API level 16
int getMinimumHeight ()

Returns the minimum height of the view.

Related XML Attributes:

Returns
int the minimum height the view will try to be.

See also:

getMinimumWidth

Added in API level 16
int getMinimumWidth ()

Returns the minimum width of the view.

Related XML Attributes:

Returns
int the minimum width the view will try to be.

See also:

getNextFocusDownId

Added in API level 1
int getNextFocusDownId ()

Gets the id of the view to use when the next focus is FOCUS_DOWN.

Related XML Attributes:

Returns
int The next focus ID, or NO_ID if the framework should decide automatically.

getNextFocusForwardId

Added in API level 11
int getNextFocusForwardId ()

Gets the id of the view to use when the next focus is FOCUS_FORWARD.

Related XML Attributes:

Returns
int The next focus ID, or NO_ID if the framework should decide automatically.

getNextFocusLeftId

Added in API level 1
int getNextFocusLeftId ()

Gets the id of the view to use when the next focus is FOCUS_LEFT.

Related XML Attributes:

Returns
int The next focus ID, or NO_ID if the framework should decide automatically.

getNextFocusRightId

Added in API level 1
int getNextFocusRightId ()

Gets the id of the view to use when the next focus is FOCUS_RIGHT.

Related XML Attributes:

Returns
int The next focus ID, or NO_ID if the framework should decide automatically.

getNextFocusUpId

Added in API level 1
int getNextFocusUpId ()

Gets the id of the view to use when the next focus is FOCUS_UP.

Related XML Attributes:

Returns
int The next focus ID, or NO_ID if the framework should decide automatically.

getOnFocusChangeListener

Added in API level 1
View.OnFocusChangeListener getOnFocusChangeListener ()

Returns the focus-change callback registered for this view.

Returns
View.OnFocusChangeListener The callback, or null if one is not registered.

getOutlineProvider

Added in API level 21
ViewOutlineProvider getOutlineProvider ()

Returns the current ViewOutlineProvider of the view, which generates the Outline that defines the shape of the shadow it casts, and enables outline clipping.

Returns
ViewOutlineProvider

See also:

getOverScrollMode

Added in API level 9
int getOverScrollMode ()

Returns the over-scroll mode for this view. The result will be one of OVER_SCROLL_ALWAYS (default), OVER_SCROLL_IF_CONTENT_SCROLLS (allow over-scrolling only if the view content is larger than the container), or OVER_SCROLL_NEVER.

Returns
int This view's over-scroll mode.

getOverlay

Added in API level 18
ViewOverlay getOverlay ()

Returns the overlay for this view, creating it if it does not yet exist. Adding drawables to the overlay will cause them to be displayed whenever the view itself is redrawn. Objects in the overlay should be actively managed: remove them when they should not be displayed anymore. The overlay will always have the same size as its host view.

Note: Overlays do not currently work correctly with SurfaceView or TextureView; contents in overlays for these types of views may not display correctly.

Returns
ViewOverlay The ViewOverlay object for this view.

See also:

getPaddingBottom

Added in API level 1
int getPaddingBottom ()

Returns the bottom padding of this view. If there are inset and enabled scrollbars, this value may include the space required to display the scrollbars as well.

Returns
int the bottom padding in pixels

getPaddingEnd

Added in API level 17
int getPaddingEnd ()

Returns the end padding of this view depending on its resolved layout direction. If there are inset and enabled scrollbars, this value may include the space required to display the scrollbars as well.

Returns
int the end padding in pixels

getPaddingLeft

Added in API level 1
int getPaddingLeft ()

Returns the left padding of this view. If there are inset and enabled scrollbars, this value may include the space required to display the scrollbars as well.

Returns
int the left padding in pixels

getPaddingRight

Added in API level 1
int getPaddingRight ()

Returns the right padding of this view. If there are inset and enabled scrollbars, this value may include the space required to display the scrollbars as well.

Returns
int the right padding in pixels

getPaddingStart

Added in API level 17
int getPaddingStart ()

Returns the start padding of this view depending on its resolved layout direction. If there are inset and enabled scrollbars, this value may include the space required to display the scrollbars as well.

Returns
int the start padding in pixels

getPaddingTop

Added in API level 1
int getPaddingTop ()

Returns the top padding of this view.

Returns
int the top padding in pixels

getParent

Added in API level 1
ViewParent getParent ()

Gets the parent of this view. Note that the parent is a ViewParent and not necessarily a View.

Returns
ViewParent Parent of this view.

getParentForAccessibility

Added in API level 16
ViewParent getParentForAccessibility ()

Gets the parent for accessibility purposes. Note that the parent for accessibility is not necessary the immediate parent. It is the first predecessor that is important for accessibility.

Returns
ViewParent The parent for accessibility purposes.

getPivotX

Added in API level 11
float getPivotX ()

The x location of the point around which the view is rotated and scaled.

Related XML Attributes:

Returns
float The x location of the pivot point.

See also:

getPivotY

Added in API level 11
float getPivotY ()

The y location of the point around which the view is rotated and scaled.

Related XML Attributes:

Returns
float The y location of the pivot point.

See also:

getPointerIcon

Added in API level 24
PointerIcon getPointerIcon ()

Gets the pointer icon for the current view.

Returns
PointerIcon

getResources

Added in API level 1
Resources getResources ()

Returns the resources associated with this view.

Returns
Resources Resources object.

getRight

Added in API level 1
int getRight ()

Right position of this view relative to its parent.

Returns
int The right edge of this view, in pixels.

getRootView

Added in API level 1
View getRootView ()

Finds the topmost view in the current view hierarchy.

Returns
View the topmost view containing this view

getRootWindowInsets

Added in API level 23
WindowInsets getRootWindowInsets ()

Provide original WindowInsets that are dispatched to the view hierarchy. The insets are only available if the view is attached.

Returns
WindowInsets WindowInsets from the top of the view hierarchy or null if View is detached

getRotation

Added in API level 11
float getRotation ()

The degrees that the view is rotated around the pivot point.

Returns
float The degrees of rotation.

See also:

getRotationX

Added in API level 11
float getRotationX ()

The degrees that the view is rotated around the horizontal axis through the pivot point.

Returns
float The degrees of X rotation.

See also:

getRotationY

Added in API level 11
float getRotationY ()

The degrees that the view is rotated around the vertical axis through the pivot point.

Returns
float The degrees of Y rotation.

See also:

getScaleX

Added in API level 11
float getScaleX ()

The amount that the view is scaled in x around the pivot point, as a proportion of the view's unscaled width. A value of 1, the default, means that no scaling is applied.

By default, this is 1.0f.

Returns
float The scaling factor.

See also:

getScaleY

Added in API level 11
float getScaleY ()

The amount that the view is scaled in y around the pivot point, as a proportion of the view's unscaled height. A value of 1, the default, means that no scaling is applied.

By default, this is 1.0f.

Returns
float The scaling factor.

See also:

getScrollBarDefaultDelayBeforeFade

Added in API level 16
int getScrollBarDefaultDelayBeforeFade ()

Returns the delay before scrollbars fade.

Related XML Attributes:

Returns
int the delay before scrollbars fade

getScrollBarFadeDuration

Added in API level 16
int getScrollBarFadeDuration ()

Returns the scrollbar fade duration.

Related XML Attributes:

Returns
int the scrollbar fade duration

getScrollBarSize

Added in API level 16
int getScrollBarSize ()

Returns the scrollbar size.

Related XML Attributes:

Returns
int the scrollbar size

getScrollBarStyle

Added in API level 1
int getScrollBarStyle ()

Returns the current scrollbar style.

Related XML Attributes:

Returns
int the current scrollbar style

See also:

getScrollIndicators

Added in API level 23
int getScrollIndicators ()

Returns a bitmask representing the enabled scroll indicators.

For example, if the top and left scroll indicators are enabled and all other indicators are disabled, the return value will be View.SCROLL_INDICATOR_TOP | View.SCROLL_INDICATOR_LEFT.

To check whether the bottom scroll indicator is enabled, use the value of (getScrollIndicators() & View.SCROLL_INDICATOR_BOTTOM) != 0.

Returns
int a bitmask representing the enabled scroll indicators

getScrollX

Added in API level 1
int getScrollX ()

Return the scrolled left position of this view. This is the left edge of the displayed part of your view. You do not need to draw any pixels farther left, since those are outside of the frame of your view on screen.

Returns
int The left edge of the displayed part of your view, in pixels.

getScrollY

Added in API level 1
int getScrollY ()

Return the scrolled top position of this view. This is the top edge of the displayed part of your view. You do not need to draw any pixels above it, since those are outside of the frame of your view on screen.

Returns
int The top edge of the displayed part of your view, in pixels.

getSolidColor

Added in API level 1
int getSolidColor ()

Override this if your view is known to always be drawn on top of a solid color background, and needs to draw fading edges. Returning a non-zero color enables the view system to optimize the drawing of the fading edges. If you do return a non-zero color, the alpha should be set to 0xFF.

Returns
int The known solid color background for this view, or 0 if the color may vary

See also:

getStateListAnimator

Added in API level 21
StateListAnimator getStateListAnimator ()

Returns the current StateListAnimator if exists.

Returns
StateListAnimator StateListAnimator or null if it does not exists

See also:

getTag

Added in API level 1
Object getTag ()

Returns this view's tag.

Returns
Object the Object stored in this view as a tag, or null if not set

See also:

getTag

Added in API level 4
Object getTag (int key)

Returns the tag associated with this view and the specified key.

Parameters
key int: The key identifying the tag
Returns
Object the Object stored in this view as a tag, or null if not set

See also:

getTextAlignment

Added in API level 17
int getTextAlignment ()

Return the resolved text alignment.

Related XML Attributes:

Returns
int the resolved text alignment. Returns one of: TEXT_ALIGNMENT_GRAVITY, TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TEXT_START, TEXT_ALIGNMENT_TEXT_END, TEXT_ALIGNMENT_VIEW_START, TEXT_ALIGNMENT_VIEW_END

getTextDirection

Added in API level 17
int getTextDirection ()

Return the resolved text direction.

Related XML Attributes:

Returns
int the resolved text direction. Returns one of: TEXT_DIRECTION_FIRST_STRONG, TEXT_DIRECTION_ANY_RTL, TEXT_DIRECTION_LTR, TEXT_DIRECTION_RTL, TEXT_DIRECTION_LOCALE, TEXT_DIRECTION_FIRST_STRONG_LTR, TEXT_DIRECTION_FIRST_STRONG_RTL

getTop

Added in API level 1
int getTop ()

Top position of this view relative to its parent.

Returns
int The top of this view, in pixels.

getTouchDelegate

Added in API level 1
TouchDelegate getTouchDelegate ()

Gets the TouchDelegate for this View.

Returns
TouchDelegate

getTouchables

Added in API level 1
ArrayList<View> getTouchables ()

Find and return all touchable views that are descendants of this view, possibly including this view if it is touchable itself.

Returns
ArrayList<View> A list of touchable views

getTransitionName

Added in API level 21
String getTransitionName ()

Returns the name of the View to be used to identify Views in Transitions. Names should be unique in the View hierarchy.

This returns null if the View has not been given a name.

Returns
String The name used of the View to be used to identify Views in Transitions or null if no name has been given.

getTranslationX

Added in API level 11
float getTranslationX ()

The horizontal location of this view relative to its left position. This position is post-layout, in addition to wherever the object's layout placed it.

Returns
float The horizontal position of this view relative to its left position, in pixels.

getTranslationY

Added in API level 11
float getTranslationY ()

The vertical location of this view relative to its top position. This position is post-layout, in addition to wherever the object's layout placed it.

Returns
float The vertical position of this view relative to its top position, in pixels.

getTranslationZ

Added in API level 21
float getTranslationZ ()

The depth location of this view relative to its elevation.

Returns
float The depth of this view relative to its elevation.

getVerticalFadingEdgeLength

Added in API level 1
int getVerticalFadingEdgeLength ()

Returns the size of the vertical faded edges used to indicate that more content in this view is visible.

Related XML Attributes:

Returns
int The size in pixels of the vertical faded edge or 0 if vertical faded edges are not enabled for this view.

getVerticalScrollbarPosition

Added in API level 11
int getVerticalScrollbarPosition ()

Returns
int The position where the vertical scroll bar will show, if applicable.

See also:

getVerticalScrollbarWidth

Added in API level 1
int getVerticalScrollbarWidth ()

Returns the width of the vertical scrollbar.

Returns
int The width in pixels of the vertical scrollbar or 0 if there is no vertical scrollbar.

getViewTreeObserver

Added in API level 1
ViewTreeObserver getViewTreeObserver ()

Returns the ViewTreeObserver for this view's hierarchy. The view tree observer can be used to get notifications when global events, like layout, happen. The returned ViewTreeObserver observer is not guaranteed to remain valid for the lifetime of this View. If the caller of this method keeps a long-lived reference to ViewTreeObserver, it should always check for the return value of isAlive().

Returns
ViewTreeObserver The ViewTreeObserver for this view's hierarchy.

getVisibility

Added in API level 1
int getVisibility ()

Returns the visibility status for this view.

Related XML Attributes:

Returns
int One of VISIBLE, INVISIBLE, or GONE.

getWidth

Added in API level 1
int getWidth ()

Return the width of the your view.

Returns
int The width of your view, in pixels.

getWindowId

Added in API level 18
WindowId getWindowId ()

Retrieve the WindowId for the window this view is currently attached to.

Returns
WindowId

getWindowSystemUiVisibility

Added in API level 16
int getWindowSystemUiVisibility ()

Returns the current system UI visibility that is currently set for the entire window. This is the combination of the setSystemUiVisibility(int) values supplied by all of the views in the window.

Returns
int

getWindowToken

Added in API level 1
IBinder getWindowToken ()

Retrieve a unique token identifying the window this view is attached to.

Returns
IBinder Return the window's token for use in WindowManager.LayoutParams.token.

getWindowVisibility

Added in API level 1
int getWindowVisibility ()

Returns the current visibility of the window this view is attached to (either GONE, INVISIBLE, or VISIBLE).

Returns
int Returns the current visibility of the view's window.

getWindowVisibleDisplayFrame

Added in API level 3
void getWindowVisibleDisplayFrame (Rect outRect)

Retrieve the overall visible display size in which the window this view is attached to has been positioned in. This takes into account screen decorations above the window, for both cases where the window itself is being position inside of them or the window is being placed under then and covered insets are used for the window to position its content inside. In effect, this tells you the available area where content can be placed and remain visible to users.

This function requires an IPC back to the window manager to retrieve the requested information, so should not be used in performance critical code like drawing.

Parameters
outRect Rect: Filled in with the visible display frame. If the view is not attached to a window, this is simply the raw display size.

getX

Added in API level 11
float getX ()

The visual x position of this view, in pixels. This is equivalent to the translationX property plus the current left property.

Returns
float The visual x position of this view, in pixels.

getY

Added in API level 11
float getY ()

The visual y position of this view, in pixels. This is equivalent to the translationY property plus the current top property.

Returns
float The visual y position of this view, in pixels.

getZ

Added in API level 21
float getZ ()

The visual z position of this view, in pixels. This is equivalent to the translationZ property plus the current elevation property.

Returns
float The visual z position of this view, in pixels.

hasFocus

Added in API level 1
boolean hasFocus ()

Returns true if this view has focus itself, or is the ancestor of the view that has focus.

Returns
boolean True if this view has or contains focus, false otherwise.

hasFocusable

Added in API level 1
boolean hasFocusable ()

Returns true if this view is focusable or if it contains a reachable View for which hasFocusable() returns true. A "reachable hasFocusable()" is a View whose parents do not block descendants focus. Only VISIBLE views are considered focusable.

Returns
boolean True if the view is focusable or if the view contains a focusable View, false otherwise.

See also:

hasNestedScrollingParent

Added in API level 21
boolean hasNestedScrollingParent ()

Returns true if this view has a nested scrolling parent.

The presence of a nested scrolling parent indicates that this view has initiated a nested scroll and it was accepted by an ancestor view further up the view hierarchy.

Returns
boolean whether this view has a nested scrolling parent

hasOnClickListeners

Added in API level 15
boolean hasOnClickListeners ()

Return whether this view has an attached OnClickListener. Returns true if there is a listener, false if there is none.

Returns
boolean

hasOverlappingRendering

Added in API level 16
boolean hasOverlappingRendering ()

Returns whether this View has content which overlaps.

This function, intended to be overridden by specific View types, is an optimization when alpha is set on a view. If rendering overlaps in a view with alpha < 1, that view is drawn to an offscreen buffer and then composited into place, which can be expensive. If the view has no overlapping rendering, the view can draw each primitive with the appropriate alpha value directly. An example of overlapping rendering is a TextView with a background image, such as a Button. An example of non-overlapping rendering is a TextView with no background, or an ImageView with only the foreground image. The default implementation returns true; subclasses should override if they have cases which can be optimized.

The current implementation of the saveLayer and saveLayerAlpha methods in Canvas necessitates that a View return true if it uses the methods internally without passing the CLIP_TO_LAYER_SAVE_FLAG.

Note: The return value of this method is ignored if forceHasOverlappingRendering(boolean) has been called on this view.

Returns
boolean true if the content in this view might overlap, false otherwise.

hasTransientState

Added in API level 16
boolean hasTransientState ()

Indicates whether the view is currently tracking transient state that the app should not need to concern itself with saving and restoring, but that the framework should take special note to preserve when possible.

A view with transient state cannot be trivially rebound from an external data source, such as an adapter binding item views in a list. This may be because the view is performing an animation, tracking user selection of content, or similar.

Returns
boolean true if the view has transient state

hasWindowFocus

Added in API level 1
boolean hasWindowFocus ()

Returns true if this view is in a window that currently has window focus. Note that this is not the same as the view itself having focus.

Returns
boolean True if this view is in a window that currently has window focus.

inflate

Added in API level 1
View inflate (Context context, 
                int resource, 
                ViewGroup root)

Inflate a view from an XML resource. This convenience method wraps the LayoutInflater class, which provides a full range of options for view inflation.

Parameters
context Context: The Context object for your activity or application.
resource int: The resource ID to inflate
root ViewGroup: A view group that will be the parent. Used to properly inflate the layout_* parameters.
Returns
View

See also:

invalidate

Added in API level 1
void invalidate ()

Invalidate the whole view. If the view is visible, onDraw(android.graphics.Canvas) will be called at some point in the future.

This must be called from a UI thread. To call from a non-UI thread, call postInvalidate().

invalidate

Added in API level 1
void invalidate (Rect dirty)

Mark the area defined by dirty as needing to be drawn. If the view is visible, onDraw(android.graphics.Canvas) will be called at some point in the future.

This must be called from a UI thread. To call from a non-UI thread, call postInvalidate().

WARNING: In API 19 and below, this method may be destructive to dirty.

Parameters
dirty Rect: the rectangle representing the bounds of the dirty region

invalidate

Added in API level 1
void invalidate (int l, 
                int t, 
                int r, 
                int b)

Mark the area defined by the rect (l,t,r,b) as needing to be drawn. The coordinates of the dirty rect are relative to the view. If the view is visible, onDraw(android.graphics.Canvas) will be called at some point in the future.

This must be called from a UI thread. To call from a non-UI thread, call postInvalidate().

Parameters
l int: the left position of the dirty region
t int: the top position of the dirty region
r int: the right position of the dirty region
b int: the bottom position of the dirty region

invalidateDrawable

Added in API level 1
void invalidateDrawable (Drawable drawable)

Invalidates the specified Drawable.

Parameters
drawable Drawable: the drawable to invalidate

invalidateOutline

Added in API level 21
void invalidateOutline ()

Called to rebuild this View's Outline from its outline provider

See also:

isAccessibilityFocused

Added in API level 21
boolean isAccessibilityFocused ()

Returns whether this View is accessibility focused.

Returns
boolean True if this View is accessibility focused.

isActivated

Added in API level 11
boolean isActivated ()

Indicates the activation state of this view.

Returns
boolean true if the view is activated, false otherwise

isAttachedToWindow

Added in API level 19
boolean isAttachedToWindow ()

Returns true if this view is currently attached to a window.

Returns
boolean

isClickable

Added in API level 1
boolean isClickable ()

Indicates whether this view reacts to click events or not.

Related XML Attributes:

Returns
boolean true if the view is clickable, false otherwise

See also:

isContextClickable

Added in API level 23
boolean isContextClickable ()

Indicates whether this view reacts to context clicks or not.

Related XML Attributes:

Returns
boolean true if the view is context clickable, false otherwise

See also:

isDirty

Added in API level 11
boolean isDirty ()

True if this view has changed since the last time being drawn.

Returns
boolean The dirty state of this view.

isDrawingCacheEnabled

Added in API level 1
boolean isDrawingCacheEnabled ()

Indicates whether the drawing cache is enabled for this view.

Returns
boolean true if the drawing cache is enabled

See also:

isDuplicateParentStateEnabled

Added in API level 1
boolean isDuplicateParentStateEnabled ()

Indicates whether this duplicates its drawable state from its parent.

Returns
boolean True if this view's drawable state is duplicated from the parent, false otherwise

See also:

isEnabled

Added in API level 1
boolean isEnabled ()

Returns the enabled status for this view. The interpretation of the enabled state varies by subclass.

Returns
boolean True if this view is enabled, false otherwise.

isFocusable

Added in API level 1
boolean isFocusable ()

Returns whether this View is able to take focus.

Related XML Attributes:

Returns
boolean True if this view can take focus, or false otherwise.

isFocusableInTouchMode

Added in API level 1
boolean isFocusableInTouchMode ()

When a view is focusable, it may not want to take focus when in touch mode. For example, a button would like focus when the user is navigating via a D-pad so that the user can click on it, but once the user starts touching the screen, the button shouldn't take focus

Related XML Attributes:

Returns
boolean Whether the view is focusable in touch mode.

isFocused

Added in API level 1
boolean isFocused ()

Returns true if this view has focus

Returns
boolean True if this view has focus, false otherwise.

isHapticFeedbackEnabled

Added in API level 3
boolean isHapticFeedbackEnabled ()

Related XML Attributes:

Returns
boolean whether this view should have haptic feedback enabled for events long presses.

See also:

isHardwareAccelerated

Added in API level 11
boolean isHardwareAccelerated ()

Indicates whether this view is attached to a hardware accelerated window or not.

Even if this method returns true, it does not mean that every call to draw(android.graphics.Canvas) will be made with an hardware accelerated Canvas. For instance, if this view is drawn onto an offscreen Bitmap and its window is hardware accelerated, isHardwareAccelerated() will likely return false, and this method will return true.

Returns
boolean True if the view is attached to a window and the window is hardware accelerated; false in any other case.

isHorizontalFadingEdgeEnabled

Added in API level 1
boolean isHorizontalFadingEdgeEnabled ()

Indicate whether the horizontal edges are faded when the view is scrolled horizontally.

Related XML Attributes:

Returns
boolean true if the horizontal edges should are faded on scroll, false otherwise

See also:

isHorizontalScrollBarEnabled

Added in API level 1
boolean isHorizontalScrollBarEnabled ()

Indicate whether the horizontal scrollbar should be drawn or not. The scrollbar is not drawn by default.

Returns
boolean true if the horizontal scrollbar should be painted, false otherwise

See also:

isHovered

Added in API level 14
boolean isHovered ()

Returns true if the view is currently hovered.

Returns
boolean True if the view is currently hovered.

See also:

isImportantForAccessibility

Added in API level 21
boolean isImportantForAccessibility ()

Computes whether this view should be exposed for accessibility. In general, views that are interactive or provide information are exposed while views that serve only as containers are hidden.

If an ancestor of this view has importance IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS, this method returns false.

Otherwise, the value is computed according to the view's getImportantForAccessibility() value:

  1. IMPORTANT_FOR_ACCESSIBILITY_NO or IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS, return false
  2. IMPORTANT_FOR_ACCESSIBILITY_YES, return true
  3. IMPORTANT_FOR_ACCESSIBILITY_AUTO, return true if view satisfies any of the following:

Returns
boolean Whether the view is exposed for accessibility.

See also:

isInEditMode

Added in API level 3
boolean isInEditMode ()

Indicates whether this View is currently in edit mode. A View is usually in edit mode when displayed within a developer tool. For instance, if this View is being drawn by a visual user interface builder, this method should return true. Subclasses should check the return value of this method to provide different behaviors if their normal behavior might interfere with the host environment. For instance: the class spawns a thread in its constructor, the drawing code relies on device-specific features, etc. This method is usually checked in the drawing code of custom widgets.

Returns
boolean True if this View is in edit mode, false otherwise.

isInLayout

Added in API level 18
boolean isInLayout ()

Returns whether the view hierarchy is currently undergoing a layout pass. This information is useful to avoid situations such as calling requestLayout() during a layout pass.

Returns
boolean whether the view hierarchy is currently undergoing a layout pass

isInTouchMode

Added in API level 1
boolean isInTouchMode ()

Returns whether the device is currently in touch mode. Touch mode is entered once the user begins interacting with the device by touch, and affects various things like whether focus is always visible to the user.

Returns
boolean Whether the device is in touch mode.

isLaidOut

Added in API level 19
boolean isLaidOut ()

Returns true if this view has been through at least one layout since it was last attached to or detached from a window.

Returns
boolean

isLayoutDirectionResolved

Added in API level 19
boolean isLayoutDirectionResolved ()

Returns
boolean true if layout direction has been resolved.

isLayoutRequested

Added in API level 1
boolean isLayoutRequested ()

Indicates whether or not this view's layout will be requested during the next hierarchy layout pass.

Returns
boolean true if the layout will be forced during next layout pass

isLongClickable

Added in API level 1
boolean isLongClickable ()

Indicates whether this view reacts to long click events or not.

Related XML Attributes:

Returns
boolean true if the view is long clickable, false otherwise

See also:

isNestedScrollingEnabled

Added in API level 21
boolean isNestedScrollingEnabled ()

Returns true if nested scrolling is enabled for this view.

If nested scrolling is enabled and this View class implementation supports it, this view will act as a nested scrolling child view when applicable, forwarding data about the scroll operation in progress to a compatible and cooperating nested scrolling parent.

Returns
boolean true if nested scrolling is enabled

See also:

isOpaque

Added in API level 7
boolean isOpaque ()

Indicates whether this View is opaque. An opaque View guarantees that it will draw all the pixels overlapping its bounds using a fully opaque color. Subclasses of View should override this method whenever possible to indicate whether an instance is opaque. Opaque Views are treated in a special way by the View hierarchy, possibly allowing it to perform optimizations during invalidate/draw passes.

Returns
boolean True if this View is guaranteed to be fully opaque, false otherwise.

isPaddingRelative

Added in API level 17
boolean isPaddingRelative ()

Return if the padding has been set through relative values setPaddingRelative(int, int, int, int) or through

Related XML Attributes:

Returns
boolean true if the padding is relative or false if it is not.

isPressed

Added in API level 1
boolean isPressed ()

Indicates whether the view is currently in pressed state. Unless setPressed(boolean) is explicitly called, only clickable views can enter the pressed state.

Returns
boolean true if the view is currently pressed, false otherwise

See also:

isSaveEnabled

Added in API level 1
boolean isSaveEnabled ()

Indicates whether this view will save its state (that is, whether its onSaveInstanceState() method will be called).

Related XML Attributes:

Returns
boolean Returns true if the view state saving is enabled, else false.

See also:

isSaveFromParentEnabled

Added in API level 11
boolean isSaveFromParentEnabled ()

Indicates whether the entire hierarchy under this view will save its state when a state saving traversal occurs from its parent. The default is true; if false, these views will not be saved unless saveHierarchyState(SparseArray) is called directly on this view.

Returns
boolean Returns true if the view state saving from parent is enabled, else false.

See also:

isScrollContainer

Added in API level 16
boolean isScrollContainer ()

Indicates whether this view is one of the set of scrollable containers in its window.

Related XML Attributes:

Returns
boolean whether this view is one of the set of scrollable containers in its window

isScrollbarFadingEnabled

Added in API level 5
boolean isScrollbarFadingEnabled ()

Returns true if scrollbars will fade when this view is not scrolling

Related XML Attributes:

Returns
boolean true if scrollbar fading is enabled

isSelected

Added in API level 1
boolean isSelected ()

Indicates the selection state of this view.

Returns
boolean true if the view is selected, false otherwise

isShown

Added in API level 1
boolean isShown ()

Returns the visibility of this view and all of its ancestors

Returns
boolean True if this view and all of its ancestors are VISIBLE

isSoundEffectsEnabled

Added in API level 1
boolean isSoundEffectsEnabled ()

Related XML Attributes:

Returns
boolean whether this view should have sound effects enabled for events such as clicking and touching.

See also:

isTemporarilyDetached

Added in API level 24
boolean isTemporarilyDetached ()

Returns
boolean true when the View is in the state between onStartTemporaryDetach() and onFinishTemporaryDetach().

isTextAlignmentResolved

Added in API level 19
boolean isTextAlignmentResolved ()

Returns
boolean true if text alignment is resolved.

isTextDirectionResolved

Added in API level 19
boolean isTextDirectionResolved ()

Returns
boolean true if text direction is resolved.

isVerticalFadingEdgeEnabled

Added in API level 1
boolean isVerticalFadingEdgeEnabled ()

Indicate whether the vertical edges are faded when the view is scrolled horizontally.

Related XML Attributes:

Returns
boolean true if the vertical edges should are faded on scroll, false otherwise

See also:

isVerticalScrollBarEnabled

Added in API level 1
boolean isVerticalScrollBarEnabled ()

Indicate whether the vertical scrollbar should be drawn or not. The scrollbar is not drawn by default.

Returns
boolean true if the vertical scrollbar should be painted, false otherwise

See also:

jumpDrawablesToCurrentState

Added in API level 11
void jumpDrawablesToCurrentState ()

Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.

Also calls jumpToCurrentState() if there is a StateListAnimator attached to this view.

layout

Added in API level 1
void layout (int l, 
                int t, 
                int r, 
                int b)

Assign a size and position to a view and all of its descendants

This is the second phase of the layout mechanism. (The first is measuring). In this phase, each parent calls layout on all of its children to position them. This is typically done using the child measurements that were stored in the measure pass().

Derived classes should not override this method. Derived classes with children should override onLayout. In that method, they should call layout on each of their children.

Parameters
l int: Left position, relative to parent
t int: Top position, relative to parent
r int: Right position, relative to parent
b int: Bottom position, relative to parent

measure

Added in API level 1
void measure (int widthMeasureSpec, 
                int heightMeasureSpec)

This is called to find out how big a view should be. The parent supplies constraint information in the width and height parameters.

The actual measurement work of a view is performed in onMeasure(int, int), called by this method. Therefore, only onMeasure(int, int) can and must be overridden by subclasses.

Parameters
widthMeasureSpec int: Horizontal space requirements as imposed by the parent
heightMeasureSpec int: Vertical space requirements as imposed by the parent

See also:

offsetLeftAndRight

Added in API level 1
void offsetLeftAndRight (int offset)

Offset this view's horizontal location by the specified amount of pixels.

Parameters
offset int: the number of pixels to offset the view by

offsetTopAndBottom

Added in API level 1
void offsetTopAndBottom (int offset)

Offset this view's vertical location by the specified number of pixels.

Parameters
offset int: the number of pixels to offset the view by

onApplyWindowInsets

Added in API level 20
WindowInsets onApplyWindowInsets (WindowInsets insets)

Called when the view should apply WindowInsets according to its internal policy.

This method should be overridden by views that wish to apply a policy different from or in addition to the default behavior. Clients that wish to force a view subtree to apply insets should call dispatchApplyWindowInsets(WindowInsets).

Clients may supply an View.OnApplyWindowInsetsListener to a view. If one is set it will be called during dispatch instead of this method. The listener may optionally call this method from its own implementation if it wishes to apply the view's default insets policy in addition to its own.

Implementations of this method should either return the insets parameter unchanged or a new WindowInsets cloned from the supplied insets with any insets consumed that this view applied itself. This allows new inset types added in future platform versions to pass through existing implementations unchanged without being erroneously consumed.

By default if a view's fitsSystemWindows property is set then the view will consume the system window insets and apply them as padding for the view.

Parameters
insets WindowInsets: Insets to apply
Returns
WindowInsets The supplied insets with any applied insets consumed

onCancelPendingInputEvents

Added in API level 19
void onCancelPendingInputEvents ()

Called as the result of a call to cancelPendingInputEvents() on this view or a parent view.

This method is responsible for removing any pending high-level input events that were posted to the event queue to run later. Custom view classes that post their own deferred high-level events via post(Runnable), postDelayed(Runnable, long) or Handler should override this method, call super.onCancelPendingInputEvents() and remove those callbacks as appropriate.

onCheckIsTextEditor

Added in API level 3
boolean onCheckIsTextEditor ()

Check whether the called view is a text editor, in which case it would make sense to automatically display a soft input window for it. Subclasses should override this if they implement onCreateInputConnection(EditorInfo) to return true if a call on that method would return a non-null InputConnection, and they are really a first-class editor that the user would normally start typing on when the go into a window containing your view.

The default implementation always returns false. This does not mean that its onCreateInputConnection(EditorInfo) will not be called or the user can not otherwise perform edits on your view; it is just a hint to the system that this is not the primary purpose of this view.

Returns
boolean Returns true if this view is a text editor, else false.

onCreateInputConnection

Added in API level 3
InputConnection onCreateInputConnection (EditorInfo outAttrs)

Create a new InputConnection for an InputMethod to interact with the view. The default implementation returns null, since it doesn't support input methods. You can override this to implement such support. This is only needed for views that take focus and text input.

When implementing this, you probably also want to implement onCheckIsTextEditor() to indicate you will return a non-null InputConnection.

Also, take good care to fill in the EditorInfo object correctly and in its entirety, so that the connected IME can rely on its values. For example, initialSelStart and initialSelEnd members must be filled in with the correct cursor position for IMEs to work correctly with your application.

Parameters
outAttrs EditorInfo: Fill in with attribute information about the connection.
Returns
InputConnection

onDragEvent

Added in API level 11
boolean onDragEvent (DragEvent event)

Handles drag events sent by the system following a call to startDragAndDrop().

When the system calls this method, it passes a DragEvent object. A call to getAction() returns one of the action type constants defined in DragEvent. The method uses these to determine what is happening in the drag and drop operation.

Parameters
event DragEvent: The DragEvent sent by the system. The getAction() method returns an action type constant defined in DragEvent, indicating the type of drag event represented by this object.
Returns
boolean true if the method was successful, otherwise false.

The method should return true in response to an action type of ACTION_DRAG_STARTED to receive drag events for the current operation.

The method should also return true in response to an action type of ACTION_DROP if it consumed the drop, or false if it didn't.

onDrawForeground

Added in API level 23
void onDrawForeground (Canvas canvas)

Draw any foreground content for this view.

Foreground content may consist of scroll bars, a foreground drawable or other view-specific decorations. The foreground is drawn on top of the primary view content.

Parameters
canvas Canvas: canvas to draw into

onFilterTouchEventForSecurity

Added in API level 9
boolean onFilterTouchEventForSecurity (MotionEvent event)

Filter the touch event to apply security policies.

Parameters
event MotionEvent: The motion event to be filtered.
Returns
boolean True if the event should be dispatched, false if the event should be dropped.

See also:

onFinishTemporaryDetach

Added in API level 3
void onFinishTemporaryDetach ()

Called after onStartTemporaryDetach() when the container is done changing the view.

onGenericMotionEvent

Added in API level 12
boolean onGenericMotionEvent (MotionEvent event)

Implement this method to handle generic motion events.

Generic motion events describe joystick movements, mouse hovers, track pad touches, scroll wheel movements and other input events. The source of the motion event specifies the class of input that was received. Implementations of this method must examine the bits in the source before processing the event. The following code example shows how this is done.

Generic motion events with source class SOURCE_CLASS_POINTER are delivered to the view under the pointer. All other generic motion events are delivered to the focused view.

 public boolean onGenericMotionEvent(MotionEvent event) {
     if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) {
         if (event.getAction() == MotionEvent.ACTION_MOVE) {
             // process the joystick movement...
             return true;
         }
     }
     if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) {
         switch (event.getAction()) {
             case MotionEvent.ACTION_HOVER_MOVE:
                 // process the mouse hover movement...
                 return true;
             case MotionEvent.ACTION_SCROLL:
                 // process the scroll wheel movement...
                 return true;
         }
     }
     return super.onGenericMotionEvent(event);
 }

Parameters
event MotionEvent: The generic motion event being processed.
Returns
boolean True if the event was handled, false otherwise.

onHoverChanged

Added in API level 14
void onHoverChanged (boolean hovered)

Implement this method to handle hover state changes.

This method is called whenever the hover state changes as a result of a call to setHovered(boolean).

Parameters
hovered boolean: The current hover state, as returned by isHovered().

See also:

onHoverEvent

Added in API level 14
boolean onHoverEvent (MotionEvent event)

Implement this method to handle hover events.

This method is called whenever a pointer is hovering into, over, or out of the bounds of a view and the view is not currently being touched. Hover events are represented as pointer events with action ACTION_HOVER_ENTER, ACTION_HOVER_MOVE, or ACTION_HOVER_EXIT.

  • The view receives a hover event with action ACTION_HOVER_ENTER when the pointer enters the bounds of the view.
  • The view receives a hover event with action ACTION_HOVER_MOVE when the pointer has already entered the bounds of the view and has moved.
  • The view receives a hover event with action ACTION_HOVER_EXIT when the pointer has exited the bounds of the view or when the pointer is about to go down due to a button click, tap, or similar user action that causes the view to be touched.

The view should implement this method to return true to indicate that it is handling the hover event, such as by changing its drawable state.

The default implementation calls setHovered(boolean) to update the hovered state of the view when a hover enter or hover exit event is received, if the view is enabled and is clickable. The default implementation also sends hover accessibility events.

Parameters
event MotionEvent: The motion event that describes the hover.
Returns
boolean True if the view handled the hover event.

See also:

onInitializeAccessibilityEvent

Added in API level 14
void onInitializeAccessibilityEvent (AccessibilityEvent event)

Initializes an AccessibilityEvent with information about this View which is the event source. In other words, the source of an accessibility event is the view whose state change triggered firing the event.

Example: Setting the password property of an event in addition to properties set by the super implementation:

 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
     super.onInitializeAccessibilityEvent(event);
     event.setPassword(true);
 }

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityEvent(View, AccessibilityEvent) is responsible for handling this call.

Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.

Parameters
event AccessibilityEvent: The event to initialize.

See also:

onInitializeAccessibilityNodeInfo

Added in API level 14
void onInitializeAccessibilityNodeInfo (AccessibilityNodeInfo info)

Initializes an AccessibilityNodeInfo with information about this view. The base implementation sets:

Subclasses should override this method, call the super implementation, and set additional attributes.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo) is responsible for handling this call.

Parameters
info AccessibilityNodeInfo: The instance to initialize.

onKeyDown

Added in API level 1
boolean onKeyDown (int keyCode, 
                KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyDown(): perform press of the view when KEYCODE_DPAD_CENTER or KEYCODE_ENTER is released, if the view is enabled and clickable.

Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.

Parameters
keyCode int: a key code that represents the button pressed, from KeyEvent
event KeyEvent: the KeyEvent object that defines the button action
Returns
boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyLongPress

Added in API level 5
boolean onKeyLongPress (int keyCode, 
                KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyLongPress(): always returns false (doesn't handle the event).

Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.

Parameters
keyCode int: The value in event.getKeyCode().
event KeyEvent: Description of the key event.
Returns
boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyMultiple

Added in API level 1
boolean onKeyMultiple (int keyCode, 
                int repeatCount, 
                KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyMultiple(): always returns false (doesn't handle the event).

Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.

Parameters
keyCode int: A key code that represents the button pressed, from KeyEvent.
repeatCount int: The number of times the action was made.
event KeyEvent: The KeyEvent object that defines the button action.
Returns
boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyPreIme

Added in API level 3
boolean onKeyPreIme (int keyCode, 
                KeyEvent event)

Handle a key event before it is processed by any input method associated with the view hierarchy. This can be used to intercept key events in special situations before the IME consumes them; a typical example would be handling the BACK key to update the application's UI instead of allowing the IME to see it and close itself.

Parameters
keyCode int: The value in event.getKeyCode().
event KeyEvent: Description of the key event.
Returns
boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyShortcut

Added in API level 1
boolean onKeyShortcut (int keyCode, 
                KeyEvent event)

Called on the focused view when a key shortcut event is not handled. Override this method to implement local key shortcuts for the View. Key shortcuts can also be implemented by setting the shortcut property of menu items.

Parameters
keyCode int: The value in event.getKeyCode().
event KeyEvent: Description of the key event.
Returns
boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyUp

Added in API level 1
boolean onKeyUp (int keyCode, 
                KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyUp(): perform clicking of the view when KEYCODE_DPAD_CENTER, KEYCODE_ENTER or KEYCODE_SPACE is released.

Key presses in software keyboards will generally NOT trigger this listener, although some may elect to do so in some situations. Do not rely on this to catch software key presses.

Parameters
keyCode int: A key code that represents the button pressed, from KeyEvent.
event KeyEvent: The KeyEvent object that defines the button action.
Returns
boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onPopulateAccessibilityEvent

Added in API level 14
void onPopulateAccessibilityEvent (AccessibilityEvent event)

Called from dispatchPopulateAccessibilityEvent(AccessibilityEvent) giving a chance to this View to populate the accessibility event with its text content. While this method is free to modify event attributes other than text content, doing so should normally be performed in onInitializeAccessibilityEvent(AccessibilityEvent).

Example: Adding formatted date string to an accessibility event in addition to the text added by the super implementation:

 public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
     super.onPopulateAccessibilityEvent(event);
     final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY;
     String selectedDateUtterance = DateUtils.formatDateTime(mContext,
         mCurrentDate.getTimeInMillis(), flags);
     event.getText().add(selectedDateUtterance);
 }

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onPopulateAccessibilityEvent(View, AccessibilityEvent) is responsible for handling this call.

Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.

Parameters
event AccessibilityEvent: The accessibility event which to populate.

See also:

onProvideStructure

Added in API level 23
void onProvideStructure (ViewStructure structure)

Called when assist structure is being retrieved from a view as part of Activity.onProvideAssistData.

Parameters
structure ViewStructure: Fill in with structured view data. The default implementation fills in all data that can be inferred from the view itself.

onProvideVirtualStructure

Added in API level 23
void onProvideVirtualStructure (ViewStructure structure)

Called when assist structure is being retrieved from a view as part of Activity.onProvideAssistData to generate additional virtual structure under this view. The defaullt implementation uses getAccessibilityNodeProvider() to try to generate this from the view's virtual accessibility nodes, if any. You can override this for a more optimal implementation providing this data.

Parameters
structure ViewStructure

onResolvePointerIcon

Added in API level 24
PointerIcon onResolvePointerIcon (MotionEvent event, 
                int pointerIndex)

Returns the pointer icon for the motion event, or null if it doesn't specify the icon. The default implementation does not care the location or event types, but some subclasses may use it (such as WebViews).

Parameters
event MotionEvent: The MotionEvent from a mouse
pointerIndex int: The index of the pointer for which to retrieve the PointerIcon. This will be between 0 and getPointerCount().
Returns
PointerIcon

See also:

onRtlPropertiesChanged

Added in API level 17
void onRtlPropertiesChanged (int layoutDirection)

Called when any RTL property (layout direction or text direction or text alignment) has been changed. Subclasses need to override this method to take care of cached information that depends on the resolved layout direction, or to inform child views that inherit their layout direction. The default implementation does nothing.

Parameters
layoutDirection int: the direction of the layout

See also:

onScreenStateChanged

Added in API level 16
void onScreenStateChanged (int screenState)

This method is called whenever the state of the screen this view is attached to changes. A state change will usually occurs when the screen turns on or off (whether it happens automatically or the user does it manually.)

Parameters
screenState int: The new state of the screen. Can be either SCREEN_STATE_ON or SCREEN_STATE_OFF

onStartTemporaryDetach

Added in API level 3
void onStartTemporaryDetach ()

This is called when a container is going to temporarily detach a child, with ViewGroup.detachViewFromParent. It will either be followed by onFinishTemporaryDetach() or onDetachedFromWindow() when the container is done.

onTouchEvent

Added in API level 1
boolean onTouchEvent (MotionEvent event)

Implement this method to handle touch screen motion events.

If this method is used to detect click actions, it is recommended that the actions be performed by implementing and calling performClick(). This will ensure consistent system behavior, including:

  • obeying click sound preferences
  • dispatching OnClickListener calls
  • handling ACTION_CLICK when accessibility features are enabled

Parameters
event MotionEvent: The motion event.
Returns
boolean True if the event was handled, false otherwise.

onTrackballEvent

Added in API level 1
boolean onTrackballEvent (MotionEvent event)

Implement this method to handle trackball motion events. The relative movement of the trackball since the last event can be retrieve with MotionEvent.getX() and MotionEvent.getY(). These are normalized so that a movement of 1 corresponds to the user pressing one DPAD key (so they will often be fractional values, representing the more fine-grained movement information available from a trackball).

Parameters
event MotionEvent: The motion event.
Returns
boolean True if the event was handled, false otherwise.

onVisibilityAggregated

Added in API level 24
void onVisibilityAggregated (boolean isVisible)

Called when the user-visibility of this View is potentially affected by a change to this view itself, an ancestor view or the window this view is attached to.

Parameters
isVisible boolean: true if this view and all of its ancestors are VISIBLE and this view's window is also visible

onWindowFocusChanged

Added in API level 1
void onWindowFocusChanged (boolean hasWindowFocus)

Called when the window containing this view gains or loses focus. Note that this is separate from view focus: to receive key events, both your view and its window must have focus. If a window is displayed on top of yours that takes input focus, then your own window will lose focus but the view focus will remain unchanged.

Parameters
hasWindowFocus boolean: True if the window containing this view now has focus, false otherwise.

onWindowSystemUiVisibilityChanged

Added in API level 16
void onWindowSystemUiVisibilityChanged (int visible)

Override to find out when the window's requested system UI visibility has changed, that is the value returned by getWindowSystemUiVisibility(). This is different from the callbacks received through setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener) in that this is only telling you about the local request of the window, not the actual values applied by the system.

Parameters
visible int

performAccessibilityAction

Added in API level 16
boolean performAccessibilityAction (int action, 
                Bundle arguments)

Performs the specified accessibility action on the view. For possible accessibility actions look at AccessibilityNodeInfo.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its performAccessibilityAction(View, int, Bundle) is responsible for handling this call.

The default implementation will delegate ACTION_SCROLL_BACKWARD and ACTION_SCROLL_FORWARD to nested scrolling parents if nested scrolling is enabled on this view.

Parameters
action int: The action to perform.
arguments Bundle: Optional action arguments.
Returns
boolean Whether the action was performed.

performClick

Added in API level 1
boolean performClick ()

Call this view's OnClickListener, if it is defined. Performs all normal actions associated with clicking: reporting accessibility event, playing a sound, etc.

Returns
boolean True there was an assigned OnClickListener that was called, false otherwise is returned.

performContextClick

Added in API level 24
boolean performContextClick (float x, 
                float y)

Call this view's OnContextClickListener, if it is defined.

Parameters
x float: the x coordinate of the context click
y float: the y coordinate of the context click
Returns
boolean True if there was an assigned OnContextClickListener that consumed the event, false otherwise.

performContextClick

Added in API level 23
boolean performContextClick ()

Call this view's OnContextClickListener, if it is defined.

Returns
boolean True if there was an assigned OnContextClickListener that consumed the event, false otherwise.

performHapticFeedback

Added in API level 3
boolean performHapticFeedback (int feedbackConstant)

BZZZTT!!1!

Provide haptic feedback to the user for this view.

The framework will provide haptic feedback for some built in actions, such as long presses, but you may wish to provide feedback for your own widget.

The feedback will only be performed if isHapticFeedbackEnabled() is true.

Parameters
feedbackConstant int: One of the constants defined in HapticFeedbackConstants
Returns
boolean

performHapticFeedback

Added in API level 3
boolean performHapticFeedback (int feedbackConstant, 
                int flags)

BZZZTT!!1!

Like performHapticFeedback(int), with additional options.

Parameters
feedbackConstant int: One of the constants defined in HapticFeedbackConstants
flags int: Additional flags as per HapticFeedbackConstants.
Returns
boolean

performLongClick

Added in API level 24
boolean performLongClick (float x, 
                float y)

Calls this view's OnLongClickListener, if it is defined. Invokes the context menu if the OnLongClickListener did not consume the event, anchoring it to an (x,y) coordinate.

Parameters
x float: x coordinate of the anchoring touch event, or NaN to disable anchoring
y float: y coordinate of the anchoring touch event, or NaN to disable anchoring
Returns
boolean true if one of the above receivers consumed the event, false otherwise

performLongClick

Added in API level 1
boolean performLongClick ()

Calls this view's OnLongClickListener, if it is defined. Invokes the context menu if the OnLongClickListener did not consume the event.

Returns
boolean true if one of the above receivers consumed the event, false otherwise

playSoundEffect

Added in API level 1
void playSoundEffect (int soundConstant)

Play a sound effect for this view.

The framework will play sound effects for some built in actions, such as clicking, but you may wish to play these effects in your widget, for instance, for internal navigation.

The sound effect will only be played if sound effects are enabled by the user, and isSoundEffectsEnabled() is true.

Parameters
soundConstant int: One of the constants defined in SoundEffectConstants

post

Added in API level 1
boolean post (Runnable action)

Causes the Runnable to be added to the message queue. The runnable will be run on the user interface thread.

Parameters
action Runnable: The Runnable that will be executed.
Returns
boolean Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting.

See also:

postDelayed

Added in API level 1
boolean postDelayed (Runnable action, 
                long delayMillis)

Causes the Runnable to be added to the message queue, to be run after the specified amount of time elapses. The runnable will be run on the user interface thread.

Parameters
action Runnable: The Runnable that will be executed.
delayMillis long: The delay (in milliseconds) until the Runnable will be executed.
Returns
boolean true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed -- if the looper is quit before the delivery time of the message occurs then the message will be dropped.

See also:

postInvalidate

Added in API level 1
void postInvalidate ()

Cause an invalidate to happen on a subsequent cycle through the event loop. Use this to invalidate the View from a non-UI thread.

This method can be invoked from outside of the UI thread only when this View is attached to a window.

See also:

postInvalidate

Added in API level 1
void postInvalidate (int left, 
                int top, 
                int right, 
                int bottom)

Cause an invalidate of the specified area to happen on a subsequent cycle through the event loop. Use this to invalidate the View from a non-UI thread.

This method can be invoked from outside of the UI thread only when this View is attached to a window.

Parameters
left int: The left coordinate of the rectangle to invalidate.
top int: The top coordinate of the rectangle to invalidate.
right int: The right coordinate of the rectangle to invalidate.
bottom int: The bottom coordinate of the rectangle to invalidate.

See also:

postInvalidateDelayed

Added in API level 1
void postInvalidateDelayed (long delayMilliseconds, 
                int left, 
                int top, 
                int right, 
                int bottom)

Cause an invalidate of the specified area to happen on a subsequent cycle through the event loop. Waits for the specified amount of time.

This method can be invoked from outside of the UI thread only when this View is attached to a window.

Parameters
delayMilliseconds long: the duration in milliseconds to delay the invalidation by
left int: The left coordinate of the rectangle to invalidate.
top int: The top coordinate of the rectangle to invalidate.
right int: The right coordinate of the rectangle to invalidate.
bottom int: The bottom coordinate of the rectangle to invalidate.

See also:

postInvalidateDelayed

Added in API level 1
void postInvalidateDelayed (long delayMilliseconds)

Cause an invalidate to happen on a subsequent cycle through the event loop. Waits for the specified amount of time.

This method can be invoked from outside of the UI thread only when this View is attached to a window.

Parameters
delayMilliseconds long: the duration in milliseconds to delay the invalidation by

See also:

postInvalidateOnAnimation

Added in API level 16
void postInvalidateOnAnimation (int left, 
                int top, 
                int right, 
                int bottom)

Cause an invalidate of the specified area to happen on the next animation time step, typically the next display frame.

This method can be invoked from outside of the UI thread only when this View is attached to a window.

Parameters
left int: The left coordinate of the rectangle to invalidate.
top int: The top coordinate of the rectangle to invalidate.
right int: The right coordinate of the rectangle to invalidate.
bottom int: The bottom coordinate of the rectangle to invalidate.

See also:

postInvalidateOnAnimation

Added in API level 16
void postInvalidateOnAnimation ()

Cause an invalidate to happen on the next animation time step, typically the next display frame.

This method can be invoked from outside of the UI thread only when this View is attached to a window.

See also:

postOnAnimation

Added in API level 16
void postOnAnimation (Runnable action)

Causes the Runnable to execute on the next animation time step. The runnable will be run on the user interface thread.

Parameters
action Runnable: The Runnable that will be executed.

See also:

postOnAnimationDelayed

Added in API level 16
void postOnAnimationDelayed (Runnable action, 
                long delayMillis)

Causes the Runnable to execute on the next animation time step, after the specified amount of time elapses. The runnable will be run on the user interface thread.

Parameters
action Runnable: The Runnable that will be executed.
delayMillis long: The delay (in milliseconds) until the Runnable will be executed.

See also:

refreshDrawableState

Added in API level 1
void refreshDrawableState ()

Call this to force a view to update its drawable state. This will cause drawableStateChanged to be called on this view. Views that are interested in the new state should call getDrawableState.

See also:

removeCallbacks

Added in API level 1
boolean removeCallbacks (Runnable action)

Removes the specified Runnable from the message queue.

Parameters
action Runnable: The Runnable to remove from the message handling queue
Returns
boolean true if this view could ask the Handler to remove the Runnable, false otherwise. When the returned value is true, the Runnable may or may not have been actually removed from the message queue (for instance, if the Runnable was not in the queue already.)

See also:

removeOnAttachStateChangeListener

Added in API level 12
void removeOnAttachStateChangeListener (View.OnAttachStateChangeListener listener)

Remove a listener for attach state changes. The listener will receive no further notification of window attach/detach events.

Parameters
listener View.OnAttachStateChangeListener: Listener to remove

See also:

removeOnLayoutChangeListener

Added in API level 11
void removeOnLayoutChangeListener (View.OnLayoutChangeListener listener)

Remove a listener for layout changes.

Parameters
listener View.OnLayoutChangeListener: The listener for layout bounds change.

requestApplyInsets

Added in API level 20
void requestApplyInsets ()

Ask that a new dispatch of onApplyWindowInsets(WindowInsets) be performed.

requestFitSystemWindows

Added in API level 16
void requestFitSystemWindows ()

This method was deprecated in API level 20.
Use requestApplyInsets() for newer platform versions.

Ask that a new dispatch of fitSystemWindows(Rect) be performed.

requestFocus

Added in API level 1
boolean requestFocus (int direction)

Call this to try to give focus to a specific view or to one of its descendants and give it a hint about what direction focus is heading. A view will not actually take focus if it is not focusable (isFocusable() returns false), or if it is focusable and it is not focusable in touch mode (isFocusableInTouchMode()) while the device is in touch mode. See also focusSearch(int), which is what you call to say that you have focus, and you want your parent to look for the next one. This is equivalent to calling requestFocus(int, Rect) with null set for the previously focused rectangle.

Parameters
direction int: One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT
Returns
boolean Whether this view or one of its descendants actually took focus.

requestFocus

Added in API level 1
boolean requestFocus ()

Call this to try to give focus to a specific view or to one of its descendants. A view will not actually take focus if it is not focusable (isFocusable() returns false), or if it is focusable and it is not focusable in touch mode (isFocusableInTouchMode()) while the device is in touch mode. See also focusSearch(int), which is what you call to say that you have focus, and you want your parent to look for the next one. This is equivalent to calling requestFocus(int, Rect) with arguments FOCUS_DOWN and null.

Returns
boolean Whether this view or one of its descendants actually took focus.

requestFocus

Added in API level 1
boolean requestFocus (int direction, 
                Rect previouslyFocusedRect)

Call this to try to give focus to a specific view or to one of its descendants and give it hints about the direction and a specific rectangle that the focus is coming from. The rectangle can help give larger views a finer grained hint about where focus is coming from, and therefore, where to show selection, or forward focus change internally. A view will not actually take focus if it is not focusable (isFocusable() returns false), or if it is focusable and it is not focusable in touch mode (isFocusableInTouchMode()) while the device is in touch mode. A View will not take focus if it is not visible. A View will not take focus if one of its parents has getDescendantFocusability() equal to FOCUS_BLOCK_DESCENDANTS. See also focusSearch(int), which is what you call to say that you have focus, and you want your parent to look for the next one. You may wish to override this method if your custom View has an internal View that it wishes to forward the request to.

Parameters
direction int: One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT
previouslyFocusedRect Rect: The rectangle (in this View's coordinate system) to give a finer grained hint about where focus is coming from. May be null if there is no hint.
Returns
boolean Whether this view or one of its descendants actually took focus.

requestFocusFromTouch

Added in API level 1
boolean requestFocusFromTouch ()

Call this to try to give focus to a specific view or to one of its descendants. This is a special variant of requestFocus() that will allow views that are not focusable in touch mode to request focus when they are touched.

Returns
boolean Whether this view or one of its descendants actually took focus.

See also:

requestLayout

Added in API level 1
void requestLayout ()

Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree. This should not be called while the view hierarchy is currently in a layout pass (isInLayout(). If layout is happening, the request may be honored at the end of the current layout pass (and then layout will run again) or after the current frame is drawn and the next layout occurs.

Subclasses which override this method should call the superclass method to handle possible request-during-layout errors correctly.

requestRectangleOnScreen

Added in API level 1
boolean requestRectangleOnScreen (Rect rectangle)

Request that a rectangle of this view be visible on the screen, scrolling if necessary just enough.

A View should call this if it maintains some notion of which part of its content is interesting. For example, a text editing view should call this when its cursor moves.

The Rectangle passed into this method should be in the View's content coordinate space. It should not be affected by which part of the View is currently visible or its scroll position.

Parameters
rectangle Rect: The rectangle in the View's content coordinate space
Returns
boolean Whether any parent scrolled.

requestRectangleOnScreen

Added in API level 1
boolean requestRectangleOnScreen (Rect rectangle, 
                boolean immediate)

Request that a rectangle of this view be visible on the screen, scrolling if necessary just enough.

A View should call this if it maintains some notion of which part of its content is interesting. For example, a text editing view should call this when its cursor moves.

The Rectangle passed into this method should be in the View's content coordinate space. It should not be affected by which part of the View is currently visible or its scroll position.

When immediate is set to true, scrolling will not be animated.

Parameters
rectangle Rect: The rectangle in the View's content coordinate space
immediate boolean: True to forbid animated scrolling, false otherwise
Returns
boolean Whether any parent scrolled.

requestUnbufferedDispatch

Added in API level 21
void requestUnbufferedDispatch (MotionEvent event)

Request unbuffered dispatch of the given stream of MotionEvents to this View. Until this View receives a corresponding ACTION_UP, ask that the input system not batch MotionEvents but instead deliver them as soon as they're available. This method should only be called for touch events.

This api is not intended for most applications. Buffered dispatch provides many of benefits, and just requesting unbuffered dispatch on most MotionEvent streams will not improve your input latency. Side effects include: increased latency, jittery scrolls and inability to take advantage of system resampling. Talk to your input professional to see if requestUnbufferedDispatch(MotionEvent) is right for you.

Parameters
event MotionEvent

resolveSize

Added in API level 1
int resolveSize (int size, 
                int measureSpec)

Version of resolveSizeAndState(int, int, int) returning only the MEASURED_SIZE_MASK bits of the result.

Parameters
size int
measureSpec int
Returns
int

resolveSizeAndState

Added in API level 11
int resolveSizeAndState (int size, 
                int measureSpec, 
                int childMeasuredState)

Utility to reconcile a desired size and state, with constraints imposed by a MeasureSpec. Will take the desired size, unless a different size is imposed by the constraints. The returned value is a compound integer, with the resolved size in the MEASURED_SIZE_MASK bits and optionally the bit MEASURED_STATE_TOO_SMALL set if the resulting size is smaller than the size the view wants to be.

Parameters
size int: How big the view wants to be.
measureSpec int: Constraints imposed by the parent.
childMeasuredState int: Size information bit mask for the view's children.
Returns
int Size information bit mask as defined by MEASURED_SIZE_MASK and MEASURED_STATE_TOO_SMALL.

restoreHierarchyState

Added in API level 1
void restoreHierarchyState (SparseArray<Parcelable> container)

Restore this view hierarchy's frozen state from the given container.

Parameters
container SparseArray: The SparseArray which holds previously frozen states.

See also:

saveHierarchyState

Added in API level 1
void saveHierarchyState (SparseArray<Parcelable> container)

Store this view hierarchy's frozen state into the given container.

Parameters
container SparseArray: The SparseArray in which to save the view's state.

See also:

scheduleDrawable

Added in API level 1
void scheduleDrawable (Drawable who, 
                Runnable what, 
                long when)

Schedules an action on a drawable to occur at a specified time.

Parameters
who Drawable: the recipient of the action
what Runnable: the action to run on the drawable
when long: the time at which the action must occur. Uses the uptimeMillis() timebase.

scrollBy

Added in API level 1
void scrollBy (int x, 
                int y)

Move the scrolled position of your view. This will cause a call to onScrollChanged(int, int, int, int) and the view will be invalidated.

Parameters
x int: the amount of pixels to scroll by horizontally
y int: the amount of pixels to scroll by vertically

scrollTo

Added in API level 1
void scrollTo (int x, 
                int y)

Set the scrolled position of your view. This will cause a call to onScrollChanged(int, int, int, int) and the view will be invalidated.

Parameters
x int: the x position to scroll to
y int: the y position to scroll to

sendAccessibilityEvent

Added in API level 4
void sendAccessibilityEvent (int eventType)

Sends an accessibility event of the given type. If accessibility is not enabled this method has no effect. The default implementation calls onInitializeAccessibilityEvent(AccessibilityEvent) first to populate information about the event source (this View), then calls dispatchPopulateAccessibilityEvent(AccessibilityEvent) to populate the text content of the event source including its descendants, and last calls requestSendAccessibilityEvent(View, AccessibilityEvent) on its parent to request sending of the event to interested parties.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its sendAccessibilityEvent(View, int) is responsible for handling this call.

Parameters
eventType int: The type of the event to send, as defined by several types from AccessibilityEvent, such as TYPE_VIEW_CLICKED or TYPE_VIEW_HOVER_ENTER.

See also:

sendAccessibilityEventUnchecked

Added in API level 4
void sendAccessibilityEventUnchecked (AccessibilityEvent event)

This method behaves exactly as sendAccessibilityEvent(int) but takes as an argument an empty AccessibilityEvent and does not perform a check whether accessibility is enabled.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its sendAccessibilityEventUnchecked(View, AccessibilityEvent) is responsible for handling this call.

Parameters
event AccessibilityEvent: The event to send.

See also:

setAccessibilityDelegate

Added in API level 14
void setAccessibilityDelegate (View.AccessibilityDelegate delegate)

Sets a delegate for implementing accessibility support via composition (as opposed to inheritance). For more details, see View.AccessibilityDelegate.

Note: On platform versions prior to API 23, delegate methods on views in the android.widget.* package are called before host methods. This prevents certain properties such as class name from being modified by overriding onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo), as any changes will be overwritten by the host class.

Starting in API 23, delegate methods are called after host methods, which all properties to be modified without being overwritten by the host class.

Parameters
delegate View.AccessibilityDelegate: the object to which accessibility method calls should be delegated

See also:

setAccessibilityLiveRegion

Added in API level 19
void setAccessibilityLiveRegion (int mode)

Sets the live region mode for this view. This indicates to accessibility services whether they should automatically notify the user about changes to the view's content description or text, or to the content descriptions or text of the view's children (where applicable).

For example, in a login screen with a TextView that displays an "incorrect password" notification, that view should be marked as a live region with mode ACCESSIBILITY_LIVE_REGION_POLITE.

To disable change notifications for this view, use ACCESSIBILITY_LIVE_REGION_NONE. This is the default live region mode for most views.

To indicate that the user should be notified of changes, use ACCESSIBILITY_LIVE_REGION_POLITE.

If the view's changes should interrupt ongoing speech and notify the user immediately, use ACCESSIBILITY_LIVE_REGION_ASSERTIVE.

Related XML Attributes:

Parameters
mode int: The live region mode for this view, one of:

setAccessibilityTraversalAfter

Added in API level 22
void setAccessibilityTraversalAfter (int afterId)

Sets the id of a view after which this one is visited in accessibility traversal. A screen-reader must visit the content of the other view before the content of this one. For example, if view B is set to be after view A, then a screen-reader will traverse the entire content of A before traversing the entire content of B, regardles of what traversal strategy it is using.

Views that do not have specified before/after relationships are traversed in order determined by the screen-reader.

Setting that this view is after a view that is not important for accessibility or if this view is not important for accessibility will have no effect as the screen-reader is not aware of unimportant views.

Related XML Attributes:

Parameters
afterId int: The id of a view this one succedees in accessibility traversal.

See also:

setAccessibilityTraversalBefore

Added in API level 22
void setAccessibilityTraversalBefore (int beforeId)

Sets the id of a view before which this one is visited in accessibility traversal. A screen-reader must visit the content of this view before the content of the one it precedes. For example, if view B is set to be before view A, then a screen-reader will traverse the entire content of B before traversing the entire content of A, regardles of what traversal strategy it is using.

Views that do not have specified before/after relationships are traversed in order determined by the screen-reader.

Setting that this view is before a view that is not important for accessibility or if this view is not important for accessibility will have no effect as the screen-reader is not aware of unimportant views.

Related XML Attributes:

Parameters
beforeId int: The id of a view this one precedes in accessibility traversal.

See also:

setActivated

Added in API level 11
void setActivated (boolean activated)

Changes the activated state of this view. A view can be activated or not. Note that activation is not the same as selection. Selection is a transient property, representing the view (hierarchy) the user is currently interacting with. Activation is a longer-term state that the user can move views in and out of. For example, in a list view with single or multiple selection enabled, the views in the current selection set are activated. (Um, yeah, we are deeply sorry about the terminology here.) The activated state is propagated down to children of the view it is set on.

Parameters
activated boolean: true if the view must be activated, false otherwise

setAlpha

Added in API level 11
void setAlpha (float alpha)

Sets the opacity of the view to a value from 0 to 1, where 0 means the view is completely transparent and 1 means the view is completely opaque.

Note: setting alpha to a translucent value (0 < alpha < 1) can have significant performance implications, especially for large views. It is best to use the alpha property sparingly and transiently, as in the case of fading animations.

For a view with a frequently changing alpha, such as during a fading animation, it is strongly recommended for performance reasons to either override hasOverlappingRendering() to return false if appropriate, or setting a layer type on the view for the duration of the animation. On versions M and below, the default path for rendering an unlayered View with alpha could add multiple milliseconds of rendering cost, even for simple or small views. Starting with M, LAYER_TYPE_HARDWARE is automatically applied to the view at the rendering level.

If this view overrides onSetAlpha(int) to return true, then this view is responsible for applying the opacity itself.

On versions LOLLIPOP_MR1 and below, note that if the view is backed by a layer and is associated with a layer paint, setting an alpha value less than 1.0 will supersede the alpha of the layer paint.

Starting with M, setting a translucent alpha value will clip a View to its bounds, unless the View returns false from hasOverlappingRendering().

Related XML Attributes:

Parameters
alpha float: The opacity of the view.

See also:

setAnimation

Added in API level 1
void setAnimation (Animation animation)

Sets the next animation to play for this view. If you want the animation to play immediately, use startAnimation(android.view.animation.Animation) instead. This method provides allows fine-grained control over the start time and invalidation, but you must make sure that 1) the animation has a start time set, and 2) the view's parent (which controls animations on its children) will be invalidated when the animation is supposed to start.

Parameters
animation Animation: The next animation, or null.

setBackground

Added in API level 16
void setBackground (Drawable background)

Set the background to a given Drawable, or remove the background. If the background has padding, this View's padding is set to the background's padding. However, when a background is removed, this View's padding isn't touched. If setting the padding is desired, please use setPadding(int, int, int, int).

Parameters
background Drawable: The Drawable to use as the background, or null to remove the background

setBackgroundColor

Added in API level 1
void setBackgroundColor (int color)

Sets the background color for this view.

Parameters
color int: the color of the background

setBackgroundDrawable

Added in API level 1
void setBackgroundDrawable (Drawable background)

This method was deprecated in API level 16.
use setBackground(Drawable) instead

Parameters
background Drawable

setBackgroundResource

Added in API level 1
void setBackgroundResource (int resid)

Set the background to a given resource. The resource should refer to a Drawable object or 0 to remove the background.

Related XML Attributes:

Parameters
resid int: The identifier of the resource.

setBackgroundTintList

Added in API level 21
void setBackgroundTintList (ColorStateList tint)

Applies a tint to the background drawable. Does not modify the current tint mode, which is SRC_IN by default.

Subsequent calls to setBackground(Drawable) will automatically mutate the drawable and apply the specified tint and tint mode using setTintList(ColorStateList).

Related XML Attributes:

Parameters
tint ColorStateList: the tint to apply, may be null to clear tint

See also:

setBackgroundTintMode

Added in API level 21
void setBackgroundTintMode (PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setBackgroundTintList(ColorStateList)} to the background drawable. The default mode is SRC_IN.

Related XML Attributes:

Parameters
tintMode PorterDuff.Mode: the blending mode used to apply the tint, may be null to clear tint

See also:

setBottom

Added in API level 11
void setBottom (int bottom)

Sets the bottom position of this view relative to its parent. This method is meant to be called by the layout system and should not generally be called otherwise, because the property may be changed at any time by the layout.

Parameters
bottom int: The bottom of this view, in pixels.

setCameraDistance

Added in API level 12
void setCameraDistance (float distance)

Sets the distance along the Z axis (orthogonal to the X/Y plane on which views are drawn) from the camera to this view. The camera's distance affects 3D transformations, for instance rotations around the X and Y axis. If the rotationX or rotationY properties are changed and this view is large (more than half the size of the screen), it is recommended to always use a camera distance that's greater than the height (X axis rotation) or the width (Y axis rotation) of this view.

The distance of the camera from the view plane can have an affect on the perspective distortion of the view when it is rotated around the x or y axis. For example, a large distance will result in a large viewing angle, and there will not be much perspective distortion of the view as it rotates. A short distance may cause much more perspective distortion upon rotation, and can also result in some drawing artifacts if the rotated view ends up partially behind the camera (which is why the recommendation is to use a distance at least as far as the size of the view, if the view is to be rotated.)

The distance is expressed in "depth pixels." The default distance depends on the screen density. For instance, on a medium density display, the default distance is 1280. On a high density display, the default distance is 1920.

If you want to specify a distance that leads to visually consistent results across various densities, use the following formula:

 float scale = context.getResources().getDisplayMetrics().density;
 view.setCameraDistance(distance * scale);
 

The density scale factor of a high density display is 1.5, and 1920 = 1280 * 1.5.

Parameters
distance float: The distance in "depth pixels", if negative the opposite value is used

See also:

setClickable

Added in API level 1
void setClickable (boolean clickable)

Enables or disables click events for this view. When a view is clickable it will change its state to "pressed" on every click. Subclasses should set the view clickable to visually react to user's clicks.

Related XML Attributes:

Parameters
clickable boolean: true to make the view clickable, false otherwise

See also:

setClipBounds

Added in API level 18
void setClipBounds (Rect clipBounds)

Sets a rectangular area on this view to which the view will be clipped when it is drawn. Setting the value to null will remove the clip bounds and the view will draw normally, using its full bounds.

Parameters
clipBounds Rect: The rectangular area, in the local coordinates of this view, to which future drawing operations will be clipped.

setClipToOutline

Added in API level 21
void setClipToOutline (boolean clipToOutline)

Sets whether the View's Outline should be used to clip the contents of the View.

Only a single non-rectangular clip can be applied on a View at any time. Circular clips from a circular reveal animation take priority over Outline clipping, and child Outline clipping takes priority over Outline clipping done by a parent.

Note that this flag will only be respected if the View's Outline returns true from canClip().

Parameters
clipToOutline boolean

See also:

setContentDescription

Added in API level 4
void setContentDescription (CharSequence contentDescription)

Sets the View's content description.

A content description briefly describes the view and is primarily used for accessibility support to determine how a view should be presented to the user. In the case of a view with no textual representation, such as ImageButton, a useful content description explains what the view does. For example, an image button with a phone icon that is used to place a call may use "Call" as its content description. An image of a floppy disk that is used to save a file may use "Save".

Related XML Attributes:

Parameters
contentDescription CharSequence: The content description.

See also:

setContextClickable

Added in API level 23
void setContextClickable (boolean contextClickable)

Enables or disables context clicking for this view. This event can launch the listener.

Related XML Attributes:

Parameters
contextClickable boolean: true to make the view react to a context click, false otherwise

See also:

setDrawingCacheBackgroundColor

Added in API level 1
void setDrawingCacheBackgroundColor (int color)

Setting a solid background color for the drawing cache's bitmaps will improve performance and memory usage. Note, though that this should only be used if this view will always be drawn on top of a solid color.

Parameters
color int: The background color to use for the drawing cache's bitmap

See also:

setDrawingCacheEnabled

Added in API level 1
void setDrawingCacheEnabled (boolean enabled)

Enables or disables the drawing cache. When the drawing cache is enabled, the next call to getDrawingCache() or buildDrawingCache() will draw the view in a bitmap. Calling draw(android.graphics.Canvas) will not draw from the cache when the cache is enabled. To benefit from the cache, you must request the drawing cache by calling getDrawingCache() and draw it on screen if the returned bitmap is not null.

Enabling the drawing cache is similar to setting a layer when hardware acceleration is turned off. When hardware acceleration is turned on, enabling the drawing cache has no effect on rendering because the system uses a different mechanism for acceleration which ignores the flag. If you want to use a Bitmap for the view, even when hardware acceleration is enabled, see setLayerType(int, android.graphics.Paint) for information on how to enable software and hardware layers.

This API can be used to manually generate a bitmap copy of this view, by setting the flag to true and calling getDrawingCache().

Parameters
enabled boolean: true to enable the drawing cache, false otherwise

See also:

setDrawingCacheQuality

Added in API level 1
void setDrawingCacheQuality (int quality)

Set the drawing cache quality of this view. This value is used only when the drawing cache is enabled

Related XML Attributes:

Parameters
quality int: One of DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_LOW, or DRAWING_CACHE_QUALITY_HIGH

See also:

setDuplicateParentStateEnabled

Added in API level 1
void setDuplicateParentStateEnabled (boolean enabled)

Enables or disables the duplication of the parent's state into this view. When duplication is enabled, this view gets its drawable state from its parent rather than from its own internal properties.

Note: in the current implementation, setting this property to true after the view was added to a ViewGroup might have no effect at all. This property should always be used from XML or set to true before adding this view to a ViewGroup.

Note: if this view's parent addStateFromChildren property is enabled and this property is enabled, an exception will be thrown.

Note: if the child view uses and updates additional states which are unknown to the parent, these states should not be affected by this method.

Parameters
enabled boolean: True to enable duplication of the parent's drawable state, false to disable it.

See also:

setElevation

Added in API level 21
void setElevation (float elevation)

Sets the base elevation of this view, in pixels.

Related XML Attributes:

Parameters
elevation float

setEnabled

Added in API level 1
void setEnabled (boolean enabled)

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.

setFadingEdgeLength

Added in API level 1
void setFadingEdgeLength (int length)

Set the size of the faded edge used to indicate that more content in this view is available. Will not change whether the fading edge is enabled; use setVerticalFadingEdgeEnabled(boolean) or setHorizontalFadingEdgeEnabled(boolean) to enable the fading edge for the vertical or horizontal fading edges.

Parameters
length int: The size in pixels of the faded edge used to indicate that more content in this view is visible.

setFilterTouchesWhenObscured

Added in API level 9
void setFilterTouchesWhenObscured (boolean enabled)

Sets whether the framework should discard touches when the view's window is obscured by another visible window. Refer to the View security documentation for more details.

Related XML Attributes:

Parameters
enabled boolean: True if touch filtering should be enabled.

See also:

setFitsSystemWindows

Added in API level 14
void setFitsSystemWindows (boolean fitSystemWindows)

Sets whether or not this view should account for system screen decorations such as the status bar and inset its content; that is, controlling whether the default implementation of fitSystemWindows(Rect) will be executed. See that method for more details.

Note that if you are providing your own implementation of fitSystemWindows(Rect), then there is no need to set this flag to true -- your implementation will be overriding the default implementation that checks this flag.

Related XML Attributes:

Parameters
fitSystemWindows boolean: If true, then the default implementation of fitSystemWindows(Rect) will be executed.

See also:

setFocusable

Added in API level 1
void setFocusable (boolean focusable)

Set whether this view can receive the focus. Setting this to false will also ensure that this view is not focusable in touch mode.

Related XML Attributes:

Parameters
focusable boolean: If true, this view can receive the focus.

See also:

setFocusableInTouchMode

Added in API level 1
void setFocusableInTouchMode (boolean focusableInTouchMode)

Set whether this view can receive focus while in touch mode. Setting this to true will also ensure that this view is focusable.

Related XML Attributes:

Parameters
focusableInTouchMode boolean: If true, this view can receive the focus while in touch mode.

See also:

setForeground

Added in API level 1
void setForeground (Drawable foreground)

Supply a Drawable that is to be rendered on top of all of the content in the view.

Related XML Attributes:

Parameters
foreground Drawable: the Drawable to be drawn on top of the children

setForegroundGravity

Added in API level 23
void setForegroundGravity (int gravity)

Describes how the foreground is positioned. Defaults to START and TOP.

Related XML Attributes:

Parameters
gravity int: see Gravity

See also:

setForegroundTintList

Added in API level 21
void setForegroundTintList (ColorStateList tint)

Applies a tint to the foreground drawable. Does not modify the current tint mode, which is SRC_IN by default.

Subsequent calls to setForeground(Drawable) will automatically mutate the drawable and apply the specified tint and tint mode using setTintList(ColorStateList).

Related XML Attributes:

Parameters
tint ColorStateList: the tint to apply, may be null to clear tint

See also:

setForegroundTintMode

Added in API level 21
void setForegroundTintMode (PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setForegroundTintList(ColorStateList)} to the background drawable. The default mode is SRC_IN.

Related XML Attributes:

Parameters
tintMode PorterDuff.Mode: the blending mode used to apply the tint, may be null to clear tint

See also:

setHapticFeedbackEnabled

Added in API level 3
void setHapticFeedbackEnabled (boolean hapticFeedbackEnabled)

Set whether this view should have haptic feedback for events such as long presses.

You may wish to disable haptic feedback if your view already controls its own haptic feedback.

Related XML Attributes:

Parameters
hapticFeedbackEnabled boolean: whether haptic feedback enabled for this view.

See also:

setHasTransientState

Added in API level 16
void setHasTransientState (boolean hasTransientState)

Set whether this view is currently tracking transient state that the framework should attempt to preserve when possible. This flag is reference counted, so every call to setHasTransientState(true) should be paired with a later call to setHasTransientState(false).

A view with transient state cannot be trivially rebound from an external data source, such as an adapter binding item views in a list. This may be because the view is performing an animation, tracking user selection of content, or similar.

Parameters
hasTransientState boolean: true if this view has transient state

setHorizontalFadingEdgeEnabled

Added in API level 1
void setHorizontalFadingEdgeEnabled (boolean horizontalFadingEdgeEnabled)

Define whether the horizontal edges should be faded when this view is scrolled horizontally.

Related XML Attributes:

Parameters
horizontalFadingEdgeEnabled boolean: true if the horizontal edges should be faded when the view is scrolled horizontally

See also:

setHorizontalScrollBarEnabled

Added in API level 1
void setHorizontalScrollBarEnabled (boolean horizontalScrollBarEnabled)

Define whether the horizontal scrollbar should be drawn or not. The scrollbar is not drawn by default.

Parameters
horizontalScrollBarEnabled boolean: true if the horizontal scrollbar should be painted

See also:

setHovered

Added in API level 14
void setHovered (boolean hovered)

Sets whether the view is currently hovered.

Calling this method also changes the drawable state of the view. This enables the view to react to hover by using different drawable resources to change its appearance.

The onHoverChanged(boolean) method is called when the hovered state changes.

Parameters
hovered boolean: True if the view is hovered.

See also:

setId

Added in API level 1
void setId (int id)

Sets the identifier for this view. The identifier does not have to be unique in this view's hierarchy. The identifier should be a positive number.

Related XML Attributes:

Parameters
id int: a number used to identify the view

See also:

setImportantForAccessibility

Added in API level 16
void setImportantForAccessibility (int mode)

Sets how to determine whether this view is important for accessibility which is if it fires accessibility events and if it is reported to accessibility services that query the screen.

Related XML Attributes:

Parameters
mode int: How to determine whether this view is important for accessibility.

See also:

setKeepScreenOn

Added in API level 1
void setKeepScreenOn (boolean keepScreenOn)

Controls whether the screen should remain on, modifying the value of KEEP_SCREEN_ON.

Related XML Attributes:

Parameters
keepScreenOn boolean: Supply true to set KEEP_SCREEN_ON.

See also:

setLabelFor

Added in API level 17
void setLabelFor (int id)

Sets the id of a view for which this view serves as a label for accessibility purposes.

Parameters
id int: The labeled view id.

setLayerPaint

Added in API level 17
void setLayerPaint (Paint paint)

Updates the Paint object used with the current layer (used only if the current layer type is not set to LAYER_TYPE_NONE). Changed properties of the Paint provided to setLayerType(int, android.graphics.Paint) will be used the next time the View is redrawn, but setLayerPaint(android.graphics.Paint) must be called to ensure that the view gets redrawn immediately.

A layer is associated with an optional Paint instance that controls how the layer is composed on screen. The following properties of the paint are taken into account when composing the layer:

If this view has an alpha value set to < 1.0 by calling setAlpha(float), the alpha value of the layer's paint is superseded by this view's alpha value.

Parameters
paint Paint: The paint used to compose the layer. This argument is optional and can be null. It is ignored when the layer type is LAYER_TYPE_NONE

See also:

setLayerType

Added in API level 11
void setLayerType (int layerType, 
                Paint paint)

Specifies the type of layer backing this view. The layer can be LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE.

A layer is associated with an optional Paint instance that controls how the layer is composed on screen. The following properties of the paint are taken into account when composing the layer:

If this view has an alpha value set to < 1.0 by calling setAlpha(float), the alpha value of the layer's paint is superseded by this view's alpha value.

Refer to the documentation of LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE and LAYER_TYPE_HARDWARE for more information on when and how to use layers.

Related XML Attributes:

Parameters
layerType int: The type of layer to use with this view, must be one of LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE
paint Paint: The paint used to compose the layer. This argument is optional and can be null. It is ignored when the layer type is LAYER_TYPE_NONE

See also:

setLayoutDirection

Added in API level 17
void setLayoutDirection (int layoutDirection)

Set the layout direction for this view. This will propagate a reset of layout direction resolution to the view's children and resolve layout direction for this view.

Related XML Attributes:

Parameters
layoutDirection int: the layout direction to set. Should be one of: LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE. Resolution will be done if the value is set to LAYOUT_DIRECTION_INHERIT. The resolution proceeds up the parent chain of the view to get the value. If there is no parent, then it will return the default LAYOUT_DIRECTION_LTR.

setLayoutParams

Added in API level 1
void setLayoutParams (ViewGroup.LayoutParams params)

Set the layout parameters associated with this view. These supply parameters to the parent of this view specifying how it should be arranged. There are many subclasses of ViewGroup.LayoutParams, and these correspond to the different subclasses of ViewGroup that are responsible for arranging their children.

Parameters
params ViewGroup.LayoutParams: The layout parameters for this view, cannot be null

setLeft

Added in API level 11
void setLeft (int left)

Sets the left position of this view relative to its parent. This method is meant to be called by the layout system and should not generally be called otherwise, because the property may be changed at any time by the layout.

Parameters
left int: The left of this view, in pixels.

setLongClickable

Added in API level 1
void setLongClickable (boolean longClickable)

Enables or disables long click events for this view. When a view is long clickable it reacts to the user holding down the button for a longer duration than a tap. This event can either launch the listener or a context menu.

Related XML Attributes:

Parameters
longClickable boolean: true to make the view long clickable, false otherwise

See also:

setMinimumHeight

Added in API level 1
void setMinimumHeight (int minHeight)

Sets the minimum height of the view. It is not guaranteed the view will be able to achieve this minimum height (for example, if its parent layout constrains it with less available height).

Related XML Attributes:

Parameters
minHeight int: The minimum height the view will try to be.

See also:

setMinimumWidth

Added in API level 1
void setMinimumWidth (int minWidth)

Sets the minimum width of the view. It is not guaranteed the view will be able to achieve this minimum width (for example, if its parent layout constrains it with less available width).

Related XML Attributes:

Parameters
minWidth int: The minimum width the view will try to be.

See also:

setNestedScrollingEnabled

Added in API level 21
void setNestedScrollingEnabled (boolean enabled)

Enable or disable nested scrolling for this view.

If this property is set to true the view will be permitted to initiate nested scrolling operations with a compatible parent view in the current hierarchy. If this view does not implement nested scrolling this will have no effect. Disabling nested scrolling while a nested scroll is in progress has the effect of stopping the nested scroll.

Parameters
enabled boolean: true to enable nested scrolling, false to disable

See also:

setNextFocusDownId

Added in API level 1
void setNextFocusDownId (int nextFocusDownId)

Sets the id of the view to use when the next focus is FOCUS_DOWN.

Related XML Attributes:

Parameters
nextFocusDownId int: The next focus ID, or NO_ID if the framework should decide automatically.

setNextFocusForwardId

Added in API level 11
void setNextFocusForwardId (int nextFocusForwardId)

Sets the id of the view to use when the next focus is FOCUS_FORWARD.

Related XML Attributes:

Parameters
nextFocusForwardId int: The next focus ID, or NO_ID if the framework should decide automatically.

setNextFocusLeftId

Added in API level 1
void setNextFocusLeftId (int nextFocusLeftId)

Sets the id of the view to use when the next focus is FOCUS_LEFT.

Related XML Attributes:

Parameters
nextFocusLeftId int: The next focus ID, or NO_ID if the framework should decide automatically.

setNextFocusRightId

Added in API level 1
void setNextFocusRightId (int nextFocusRightId)

Sets the id of the view to use when the next focus is FOCUS_RIGHT.

Related XML Attributes:

Parameters
nextFocusRightId int: The next focus ID, or NO_ID if the framework should decide automatically.

setNextFocusUpId

Added in API level 1
void setNextFocusUpId (int nextFocusUpId)

Sets the id of the view to use when the next focus is FOCUS_UP.

Related XML Attributes:

Parameters
nextFocusUpId int: The next focus ID, or NO_ID if the framework should decide automatically.

setOnApplyWindowInsetsListener

Added in API level 20
void setOnApplyWindowInsetsListener (View.OnApplyWindowInsetsListener listener)

Set an View.OnApplyWindowInsetsListener to take over the policy for applying window insets to this view. The listener's onApplyWindowInsets method will be called instead of the view's onApplyWindowInsets method.

Parameters
listener View.OnApplyWindowInsetsListener: Listener to set

See also:

setOnClickListener

Added in API level 1
void setOnClickListener (View.OnClickListener l)

Register a callback to be invoked when this view is clicked. If this view is not clickable, it becomes clickable.

Parameters
l View.OnClickListener: The callback that will run

See also:

setOnContextClickListener

Added in API level 23
void setOnContextClickListener (View.OnContextClickListener l)

Register a callback to be invoked when this view is context clicked. If the view is not context clickable, it becomes context clickable.

Parameters
l View.OnContextClickListener: The callback that will run

See also:

setOnCreateContextMenuListener

Added in API level 1
void setOnCreateContextMenuListener (View.OnCreateContextMenuListener l)

Register a callback to be invoked when the context menu for this view is being built. If this view is not long clickable, it becomes long clickable.

Parameters
l View.OnCreateContextMenuListener: The callback that will run

setOnDragListener

Added in API level 11
void setOnDragListener (View.OnDragListener l)

Register a drag event listener callback object for this View. The parameter is an implementation of View.OnDragListener. To send a drag event to a View, the system calls the onDrag(View, DragEvent) method.

Parameters
l View.OnDragListener: An implementation of View.OnDragListener.

setOnFocusChangeListener

Added in API level 1
void setOnFocusChangeListener (View.OnFocusChangeListener l)

Register a callback to be invoked when focus of this view changed.

Parameters
l View.OnFocusChangeListener: The callback that will run.

setOnGenericMotionListener

Added in API level 12
void setOnGenericMotionListener (View.OnGenericMotionListener l)

Register a callback to be invoked when a generic motion event is sent to this view.

Parameters
l View.OnGenericMotionListener: the generic motion listener to attach to this view

setOnHoverListener

Added in API level 14
void setOnHoverListener (View.OnHoverListener l)

Register a callback to be invoked when a hover event is sent to this view.

Parameters
l View.OnHoverListener: the hover listener to attach to this view

setOnKeyListener

Added in API level 1
void setOnKeyListener (View.OnKeyListener l)

Register a callback to be invoked when a hardware key is pressed in this view. Key presses in software input methods will generally not trigger the methods of this listener.

Parameters
l View.OnKeyListener: the key listener to attach to this view

setOnLongClickListener

Added in API level 1
void setOnLongClickListener (View.OnLongClickListener l)

Register a callback to be invoked when this view is clicked and held. If this view is not long clickable, it becomes long clickable.

Parameters
l View.OnLongClickListener: The callback that will run

See also:

setOnScrollChangeListener

Added in API level 23
void setOnScrollChangeListener (View.OnScrollChangeListener l)

Register a callback to be invoked when the scroll X or Y positions of this view change.

Note: Some views handle scrolling independently from View and may have their own separate listeners for scroll-type events. For example, ListView allows clients to register an AbsListView.OnScrollListener to listen for changes in list scroll position.

Parameters
l View.OnScrollChangeListener: The listener to notify when the scroll X or Y position changes.

See also:

setOnSystemUiVisibilityChangeListener

Added in API level 11
void setOnSystemUiVisibilityChangeListener (View.OnSystemUiVisibilityChangeListener l)

Set a listener to receive callbacks when the visibility of the system bar changes.

Parameters
l View.OnSystemUiVisibilityChangeListener: The View.OnSystemUiVisibilityChangeListener to receive callbacks.

setOnTouchListener

Added in API level 1
void setOnTouchListener (View.OnTouchListener l)

Register a callback to be invoked when a touch event is sent to this view.

Parameters
l View.OnTouchListener: the touch listener to attach to this view

setOutlineProvider

Added in API level 21
void setOutlineProvider (ViewOutlineProvider provider)

Sets the ViewOutlineProvider of the view, which generates the Outline that defines the shape of the shadow it casts, and enables outline clipping.

The default ViewOutlineProvider, BACKGROUND, queries the Outline from the View's background drawable, via getOutline(Outline). Changing the outline provider with this method allows this behavior to be overridden.

If the ViewOutlineProvider is null, if querying it for an outline returns false, or if the produced Outline is isEmpty(), shadows will not be cast.

Only outlines that return true from canClip() may be used for clipping.

Parameters
provider ViewOutlineProvider

See also:

setOverScrollMode

Added in API level 9
void setOverScrollMode (int overScrollMode)

Set the over-scroll mode for this view. Valid over-scroll modes are OVER_SCROLL_ALWAYS (default), OVER_SCROLL_IF_CONTENT_SCROLLS (allow over-scrolling only if the view content is larger than the container), or OVER_SCROLL_NEVER. Setting the over-scroll mode of a view will have an effect only if the view is capable of scrolling.

Parameters
overScrollMode int: The new over-scroll mode for this view.

setPadding

Added in API level 1
void setPadding (int left, 
                int top, 
                int right, 
                int bottom)

Sets the padding. The view may add on the space required to display the scrollbars, depending on the style and visibility of the scrollbars. So the values returned from getPaddingLeft(), getPaddingTop(), getPaddingRight() and getPaddingBottom() may be different from the values set in this call.

Related XML Attributes:

Parameters
left int: the left padding in pixels
top int: the top padding in pixels
right int: the right padding in pixels
bottom int: the bottom padding in pixels

setPaddingRelative

Added in API level 17
void setPaddingRelative (int start, 
                int top, 
                int end, 
                int bottom)

Sets the relative padding. The view may add on the space required to display the scrollbars, depending on the style and visibility of the scrollbars. So the values returned from getPaddingStart(), getPaddingTop(), getPaddingEnd() and getPaddingBottom() may be different from the values set in this call.

Related XML Attributes:

Parameters
start int: the start padding in pixels
top int: the top padding in pixels
end int: the end padding in pixels
bottom int: the bottom padding in pixels

setPivotX

Added in API level 11
void setPivotX (float pivotX)

Sets the x location of the point around which the view is rotated and scaled. By default, the pivot point is centered on the object. Setting this property disables this behavior and causes the view to use only the explicitly set pivotX and pivotY values.

Related XML Attributes:

Parameters
pivotX float: The x location of the pivot point.

See also:

setPivotY

Added in API level 11
void setPivotY (float pivotY)

Sets the y location of the point around which the view is rotated and scaled. By default, the pivot point is centered on the object. Setting this property disables this behavior and causes the view to use only the explicitly set pivotX and pivotY values.

Related XML Attributes:

Parameters
pivotY float: The y location of the pivot point.

See also:

setPointerIcon

Added in API level 24
void setPointerIcon (PointerIcon pointerIcon)

Set the pointer icon for the current view. Passing null will restore the pointer icon to its default value.

Parameters
pointerIcon PointerIcon: A PointerIcon instance which will be shown when the mouse hovers.

setPressed

Added in API level 1
void setPressed (boolean pressed)

Sets the pressed state for this view.

Parameters
pressed boolean: Pass true to set the View's internal state to "pressed", or false to reverts the View's internal state from a previously set "pressed" state.

See also:

setRight

Added in API level 11
void setRight (int right)

Sets the right position of this view relative to its parent. This method is meant to be called by the layout system and should not generally be called otherwise, because the property may be changed at any time by the layout.

Parameters
right int: The right of this view, in pixels.

setRotation

Added in API level 11
void setRotation (float rotation)

Sets the degrees that the view is rotated around the pivot point. Increasing values result in clockwise rotation.

Related XML Attributes:

Parameters
rotation float: The degrees of rotation.

See also:

setRotationX

Added in API level 11
void setRotationX (float rotationX)

Sets the degrees that the view is rotated around the horizontal axis through the pivot point. Increasing values result in clockwise rotation from the viewpoint of looking down the x axis. When rotating large views, it is recommended to adjust the camera distance accordingly. Refer to setCameraDistance(float) for more information.

Related XML Attributes:

Parameters
rotationX float: The degrees of X rotation.

See also:

setRotationY

Added in API level 11
void setRotationY (float rotationY)

Sets the degrees that the view is rotated around the vertical axis through the pivot point. Increasing values result in counter-clockwise rotation from the viewpoint of looking down the y axis. When rotating large views, it is recommended to adjust the camera distance accordingly. Refer to setCameraDistance(float) for more information.

Related XML Attributes:

Parameters
rotationY float: The degrees of Y rotation.

See also:

setSaveEnabled

Added in API level 1
void setSaveEnabled (boolean enabled)

Controls whether the saving of this view's state is enabled (that is, whether its onSaveInstanceState() method will be called). Note that even if freezing is enabled, the view still must have an id assigned to it (via setId(int)) for its state to be saved. This flag can only disable the saving of this view; any child views may still have their state saved.

Related XML Attributes:

Parameters
enabled boolean: Set to false to disable state saving, or true (the default) to allow it.

See also:

setSaveFromParentEnabled

Added in API level 11
void setSaveFromParentEnabled (boolean enabled)

Controls whether the entire hierarchy under this view will save its state when a state saving traversal occurs from its parent. The default is true; if false, these views will not be saved unless saveHierarchyState(SparseArray) is called directly on this view.

Parameters
enabled boolean: Set to false to disable state saving, or true (the default) to allow it.

See also:

setScaleX

Added in API level 11
void setScaleX (float scaleX)

Sets the amount that the view is scaled in x around the pivot point, as a proportion of the view's unscaled width. A value of 1 means that no scaling is applied.

Related XML Attributes:

Parameters
scaleX float: The scaling factor.

See also:

setScaleY

Added in API level 11
void setScaleY (float scaleY)

Sets the amount that the view is scaled in Y around the pivot point, as a proportion of the view's unscaled width. A value of 1 means that no scaling is applied.

Related XML Attributes:

Parameters
scaleY float: The scaling factor.

See also:

setScrollBarDefaultDelayBeforeFade

Added in API level 16
void setScrollBarDefaultDelayBeforeFade (int scrollBarDefaultDelayBeforeFade)

Define the delay before scrollbars fade.

Related XML Attributes:

Parameters
scrollBarDefaultDelayBeforeFade int: - the delay before scrollbars fade

setScrollBarFadeDuration

Added in API level 16
void setScrollBarFadeDuration (int scrollBarFadeDuration)

Define the scrollbar fade duration.

Related XML Attributes:

Parameters
scrollBarFadeDuration int: - the scrollbar fade duration

setScrollBarSize

Added in API level 16
void setScrollBarSize (int scrollBarSize)

Define the scrollbar size.

Related XML Attributes:

Parameters
scrollBarSize int: - the scrollbar size

setScrollBarStyle

Added in API level 1
void setScrollBarStyle (int style)

Specify the style of the scrollbars. The scrollbars can be overlaid or inset. When inset, they add to the padding of the view. And the scrollbars can be drawn inside the padding area or on the edge of the view. For example, if a view has a background drawable and you want to draw the scrollbars inside the padding specified by the drawable, you can use SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to appear at the edge of the view, ignoring the padding, then you can use SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.

Related XML Attributes:

Parameters
style int: the style of the scrollbars. Should be one of SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.

See also:

setScrollContainer

Added in API level 3
void setScrollContainer (boolean isScrollContainer)

Change whether this view is one of the set of scrollable containers in its window. This will be used to determine whether the window can resize or must pan when a soft input area is open -- scrollable containers allow the window to use resize mode since the container will appropriately shrink.

Related XML Attributes:

Parameters
isScrollContainer boolean

setScrollIndicators

Added in API level 23
void setScrollIndicators (int indicators, 
                int mask)

Sets the state of the scroll indicators specified by the mask. To change all scroll indicators at once, see setScrollIndicators(int).

When a scroll indicator is enabled, it will be displayed if the view can scroll in the direction of the indicator.

Multiple indicator types may be enabled or disabled by passing the logical OR of the desired types. If multiple types are specified, they will all be set to the same enabled state.

For example, to enable the top scroll indicatorExample: {@code setScrollIndicators

Related XML Attributes:

Parameters
indicators int: the indicator direction, or the logical OR of multiple indicator directions. One or more of:
mask int

See also:

setScrollIndicators

Added in API level 23
void setScrollIndicators (int indicators)

Sets the state of all scroll indicators.

See setScrollIndicators(int, int) for usage information.

Related XML Attributes:

Parameters
indicators int: a bitmask of indicators that should be enabled, or 0 to disable all indicators

See also:

setScrollX

Added in API level 14
void setScrollX (int value)

Set the horizontal scrolled position of your view. This will cause a call to onScrollChanged(int, int, int, int) and the view will be invalidated.

Parameters
value int: the x position to scroll to

setScrollY

Added in API level 14
void setScrollY (int value)

Set the vertical scrolled position of your view. This will cause a call to onScrollChanged(int, int, int, int) and the view will be invalidated.

Parameters
value int: the y position to scroll to

setScrollbarFadingEnabled

Added in API level 5
void setScrollbarFadingEnabled (boolean fadeScrollbars)

Define whether scrollbars will fade when the view is not scrolling.

Related XML Attributes:

Parameters
fadeScrollbars boolean: whether to enable fading

setSelected

Added in API level 1
void setSelected (boolean selected)

Changes the selection state of this view. A view can be selected or not. Note that selection is not the same as focus. Views are typically selected in the context of an AdapterView like ListView or GridView; the selected view is the view that is highlighted.

Parameters
selected boolean: true if the view must be selected, false otherwise

setSoundEffectsEnabled

Added in API level 1
void setSoundEffectsEnabled (boolean soundEffectsEnabled)

Set whether this view should have sound effects enabled for events such as clicking and touching.

You may wish to disable sound effects for a view if you already play sounds, for instance, a dial key that plays dtmf tones.

Related XML Attributes:

Parameters
soundEffectsEnabled boolean: whether sound effects are enabled for this view.

See also:

setStateListAnimator

Added in API level 21
void setStateListAnimator (StateListAnimator stateListAnimator)

Attaches the provided StateListAnimator to this View.

Any previously attached StateListAnimator will be detached.

Parameters
stateListAnimator StateListAnimator: The StateListAnimator to update the view

See also:

setSystemUiVisibility

Added in API level 11
void setSystemUiVisibility (int visibility)

Request that the visibility of the status bar or other screen/window decorations be changed.

This method is used to put the over device UI into temporary modes where the user's attention is focused more on the application content, by dimming or hiding surrounding system affordances. This is typically used in conjunction with Window.FEATURE_ACTION_BAR_OVERLAY, allowing the applications content to be placed behind the action bar (and with these flags other system affordances) so that smooth transitions between hiding and showing them can be done.

Two representative examples of the use of system UI visibility is implementing a content browsing application (like a magazine reader) and a video playing application.

The first code shows a typical implementation of a View in a content browsing application. In this implementation, the application goes into a content-oriented mode by hiding the status bar and action bar, and putting the navigation elements into lights out mode. The user can then interact with content while in this mode. Such an application should provide an easy way for the user to toggle out of the mode (such as to check information in the status bar or access notifications). In the implementation here, this is done simply by tapping on the content.

public static class Content extends ScrollView
        implements View.OnSystemUiVisibilityChangeListener, View.OnClickListener {
    TextView mText;
    TextView mTitleView;
    SeekBar mSeekView;
    boolean mNavVisible;
    int mBaseSystemUiVisibility = SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | SYSTEM_UI_FLAG_LAYOUT_STABLE;
    int mLastSystemUiVis;

    Runnable mNavHider = new Runnable() {
        @Override public void run() {
            setNavVisibility(false);
        }
    };

    public Content(Context context, AttributeSet attrs) {
        super(context, attrs);

        mText = new TextView(context);
        mText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        mText.setText(context.getString(R.string.alert_dialog_two_buttons2ultra_msg));
        mText.setClickable(false);
        mText.setOnClickListener(this);
        mText.setTextIsSelectable(true);
        addView(mText, new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

        setOnSystemUiVisibilityChangeListener(this);
    }

    public void init(TextView title, SeekBar seek) {
        // This called by the containing activity to supply the surrounding
        // state of the content browser that it will interact with.
        mTitleView = title;
        mSeekView = seek;
        setNavVisibility(true);
    }

    @Override public void onSystemUiVisibilityChange(int visibility) {
        // Detect when we go out of low-profile mode, to also go out
        // of full screen.  We only do this when the low profile mode
        // is changing from its last state, and turning off.
        int diff = mLastSystemUiVis ^ visibility;
        mLastSystemUiVis = visibility;
        if ((diff&SYSTEM_UI_FLAG_LOW_PROFILE) != 0
                && (visibility&SYSTEM_UI_FLAG_LOW_PROFILE) == 0) {
            setNavVisibility(true);
        }
    }

    @Override protected void onWindowVisibilityChanged(int visibility) {
        super.onWindowVisibilityChanged(visibility);

        // When we become visible, we show our navigation elements briefly
        // before hiding them.
        setNavVisibility(true);
        getHandler().postDelayed(mNavHider, 2000);
    }

    @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);

        // When the user scrolls, we hide navigation elements.
        setNavVisibility(false);
    }

    @Override public void onClick(View v) {
        // When the user clicks, we toggle the visibility of navigation elements.
        int curVis = getSystemUiVisibility();
        setNavVisibility((curVis&SYSTEM_UI_FLAG_LOW_PROFILE) != 0);
    }

    void setBaseSystemUiVisibility(int visibility) {
        mBaseSystemUiVisibility = visibility;
    }

    void setNavVisibility(boolean visible) {
        int newVis = mBaseSystemUiVisibility;
        if (!visible) {
            newVis |= SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_FULLSCREEN;
        }
        final boolean changed = newVis == getSystemUiVisibility();

        // Unschedule any pending event to hide navigation if we are
        // changing the visibility, or making the UI visible.
        if (changed || visible) {
            Handler h = getHandler();
            if (h != null) {
                h.removeCallbacks(mNavHider);
            }
        }

        // Set the new desired visibility.
        setSystemUiVisibility(newVis);
        mTitleView.setVisibility(visible ? VISIBLE : INVISIBLE);
        mSeekView.setVisibility(visible ? VISIBLE : INVISIBLE);
    }
}

This second code sample shows a typical implementation of a View in a video playing application. In this situation, while the video is playing the application would like to go into a complete full-screen mode, to use as much of the display as possible for the video. When in this state the user can not interact with the application; the system intercepts touching on the screen to pop the UI out of full screen mode. See fitSystemWindows(Rect) for a sample layout that goes with this code.

public static class Content extends ImageView implements
        View.OnSystemUiVisibilityChangeListener, View.OnClickListener,
        ActionBar.OnMenuVisibilityListener {
    Activity mActivity;
    TextView mTitleView;
    Button mPlayButton;
    SeekBar mSeekView;
    boolean mAddedMenuListener;
    boolean mMenusOpen;
    boolean mPaused;
    boolean mNavVisible;
    int mLastSystemUiVis;

    Runnable mNavHider = new Runnable() {
        @Override public void run() {
            setNavVisibility(false);
        }
    };

    public Content(Context context, AttributeSet attrs) {
        super(context, attrs);
        setOnSystemUiVisibilityChangeListener(this);
        setOnClickListener(this);
    }

    public void init(Activity activity, TextView title, Button playButton,
            SeekBar seek) {
        // This called by the containing activity to supply the surrounding
        // state of the video player that it will interact with.
        mActivity = activity;
        mTitleView = title;
        mPlayButton = playButton;
        mSeekView = seek;
        mPlayButton.setOnClickListener(this);
        setPlayPaused(true);
    }

    @Override protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (mActivity != null) {
            mAddedMenuListener = true;
            mActivity.getActionBar().addOnMenuVisibilityListener(this);
        }
    }

    @Override protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if (mAddedMenuListener) {
            mActivity.getActionBar().removeOnMenuVisibilityListener(this);
        }
    }

    @Override public void onSystemUiVisibilityChange(int visibility) {
        // Detect when we go out of nav-hidden mode, to clear our state
        // back to having the full UI chrome up.  Only do this when
        // the state is changing and nav is no longer hidden.
        int diff = mLastSystemUiVis ^ visibility;
        mLastSystemUiVis = visibility;
        if ((diff&SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
                && (visibility&SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
            setNavVisibility(true);
        }
    }

    @Override protected void onWindowVisibilityChanged(int visibility) {
        super.onWindowVisibilityChanged(visibility);

        // When we become visible or invisible, play is paused.
        setPlayPaused(true);
    }

    @Override public void onClick(View v) {
        if (v == mPlayButton) {
            // Clicking on the play/pause button toggles its state.
            setPlayPaused(!mPaused);
        } else {
            // Clicking elsewhere makes the navigation visible.
            setNavVisibility(true);
        }
    }

    @Override public void onMenuVisibilityChanged(boolean isVisible) {
        mMenusOpen = isVisible;
        setNavVisibility(true);
    }

    void setPlayPaused(boolean paused) {
        mPaused = paused;
        mPlayButton.setText(paused ? R.string.play : R.string.pause);
        setKeepScreenOn(!paused);
        setNavVisibility(true);
    }

    void setNavVisibility(boolean visible) {
        int newVis = SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | SYSTEM_UI_FLAG_LAYOUT_STABLE;
        if (!visible) {
            newVis |= SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_FULLSCREEN
                    | SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        }

        // If we are now visible, schedule a timer for us to go invisible.
        if (visible) {
            Handler h = getHandler();
            if (h != null) {
                h.removeCallbacks(mNavHider);
                if (!mMenusOpen && !mPaused) {
                    // If the menus are open or play is paused, we will not auto-hide.
                    h.postDelayed(mNavHider, 3000);
                }
            }
        }

        // Set the new desired visibility.
        setSystemUiVisibility(newVis);
        mTitleView.setVisibility(visible ? VISIBLE : INVISIBLE);
        mPlayButton.setVisibility(visible ? VISIBLE : INVISIBLE);
        mSeekView.setVisibility(visible ? VISIBLE : INVISIBLE);
    }
}

Parameters
visibility int: Bitwise-or of flags SYSTEM_UI_FLAG_LOW_PROFILE, SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_FULLSCREEN, SYSTEM_UI_FLAG_LAYOUT_STABLE, SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, SYSTEM_UI_FLAG_IMMERSIVE, and SYSTEM_UI_FLAG_IMMERSIVE_STICKY.

setTag

Added in API level 4
void setTag (int key, 
                Object tag)

Sets a tag associated with this view and a key. A tag can be used to mark a view in its hierarchy and does not have to be unique within the hierarchy. Tags can also be used to store data within a view without resorting to another data structure. The specified key should be an id declared in the resources of the application to ensure it is unique (see the ID resource type). Keys identified as belonging to the Android framework or not associated with any package will cause an IllegalArgumentException to be thrown.

Parameters
key int: The key identifying the tag
tag Object: An Object to tag the view with
Throws
IllegalArgumentException If they specified key is not valid

See also:

setTag

Added in API level 1
void setTag (Object tag)

Sets the tag associated with this view. A tag can be used to mark a view in its hierarchy and does not have to be unique within the hierarchy. Tags can also be used to store data within a view without resorting to another data structure.

Parameters
tag Object: an Object to tag the view with

See also:

setTextAlignment

Added in API level 17
void setTextAlignment (int textAlignment)

Set the text alignment.

Related XML Attributes:

Parameters
textAlignment int: The text alignment to set. Should be one of TEXT_ALIGNMENT_INHERIT, TEXT_ALIGNMENT_GRAVITY, TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TEXT_START, TEXT_ALIGNMENT_TEXT_END, TEXT_ALIGNMENT_VIEW_START, TEXT_ALIGNMENT_VIEW_END Resolution will be done if the value is set to TEXT_ALIGNMENT_INHERIT. The resolution proceeds up the parent chain of the view to get the value. If there is no parent, then it will return the default TEXT_ALIGNMENT_GRAVITY.

setTextDirection

Added in API level 17
void setTextDirection (int textDirection)

Set the text direction.

Related XML Attributes:

Parameters
textDirection int: the direction to set. Should be one of: TEXT_DIRECTION_INHERIT, TEXT_DIRECTION_FIRST_STRONG, TEXT_DIRECTION_ANY_RTL, TEXT_DIRECTION_LTR, TEXT_DIRECTION_RTL, TEXT_DIRECTION_LOCALE TEXT_DIRECTION_FIRST_STRONG_LTR, TEXT_DIRECTION_FIRST_STRONG_RTL, Resolution will be done if the value is set to TEXT_DIRECTION_INHERIT. The resolution proceeds up the parent chain of the view to get the value. If there is no parent, then it will return the default TEXT_DIRECTION_FIRST_STRONG.

setTop

Added in API level 11
void setTop (int top)

Sets the top position of this view relative to its parent. This method is meant to be called by the layout system and should not generally be called otherwise, because the property may be changed at any time by the layout.

Parameters
top int: The top of this view, in pixels.

setTouchDelegate

Added in API level 1
void setTouchDelegate (TouchDelegate delegate)

Sets the TouchDelegate for this View.

Parameters
delegate TouchDelegate

setTransitionName

Added in API level 21
void setTransitionName (String transitionName)

Sets the name of the View to be used to identify Views in Transitions. Names should be unique in the View hierarchy.

Parameters
transitionName String: The name of the View to uniquely identify it for Transitions.

setTranslationX

Added in API level 11
void setTranslationX (float translationX)

Sets the horizontal location of this view relative to its left position. This effectively positions the object post-layout, in addition to wherever the object's layout placed it.

Related XML Attributes:

Parameters
translationX float: The horizontal position of this view relative to its left position, in pixels.

setTranslationY

Added in API level 11
void setTranslationY (float translationY)

Sets the vertical location of this view relative to its top position. This effectively positions the object post-layout, in addition to wherever the object's layout placed it.

Related XML Attributes:

Parameters
translationY float: The vertical position of this view relative to its top position, in pixels.

setTranslationZ

Added in API level 21
void setTranslationZ (float translationZ)

Sets the depth location of this view relative to its elevation.

Related XML Attributes:

Parameters
translationZ float

setVerticalFadingEdgeEnabled

Added in API level 1
void setVerticalFadingEdgeEnabled (boolean verticalFadingEdgeEnabled)

Define whether the vertical edges should be faded when this view is scrolled vertically.

Related XML Attributes:

Parameters
verticalFadingEdgeEnabled boolean: true if the vertical edges should be faded when the view is scrolled vertically

See also:

setVerticalScrollBarEnabled

Added in API level 1
void setVerticalScrollBarEnabled (boolean verticalScrollBarEnabled)

Define whether the vertical scrollbar should be drawn or not. The scrollbar is not drawn by default.

Parameters
verticalScrollBarEnabled boolean: true if the vertical scrollbar should be painted

See also:

setVerticalScrollbarPosition

Added in API level 11
void setVerticalScrollbarPosition (int position)

Set the position of the vertical scroll bar. Should be one of SCROLLBAR_POSITION_DEFAULT, SCROLLBAR_POSITION_LEFT or SCROLLBAR_POSITION_RIGHT.

Parameters
position int: Where the vertical scroll bar should be positioned.

setVisibility

Added in API level 1
void setVisibility (int visibility)

Set the enabled state of this view.

Related XML Attributes:

Parameters
visibility int: One of VISIBLE, INVISIBLE, or GONE.

setWillNotCacheDrawing

Added in API level 1
void setWillNotCacheDrawing (boolean willNotCacheDrawing)

When a View's drawing cache is enabled, drawing is redirected to an offscreen bitmap. Some views, like an ImageView, must be able to bypass this mechanism if they already draw a single bitmap, to avoid unnecessary usage of the memory.

Parameters
willNotCacheDrawing boolean: true if this view does not cache its drawing, false otherwise

setWillNotDraw

Added in API level 1
void setWillNotDraw (boolean willNotDraw)

If this view doesn't do any drawing on its own, set this flag to allow further optimizations. By default, this flag is not set on View, but could be set on some View subclasses such as ViewGroup. Typically, if you override onDraw(android.graphics.Canvas) you should clear this flag.

Parameters
willNotDraw boolean: whether or not this View draw on its own

setX

Added in API level 11
void setX (float x)

Sets the visual x position of this view, in pixels. This is equivalent to setting the translationX property to be the difference between the x value passed in and the current left property.

Parameters
x float: The visual x position of this view, in pixels.

setY

Added in API level 11
void setY (float y)

Sets the visual y position of this view, in pixels. This is equivalent to setting the translationY property to be the difference between the y value passed in and the current top property.

Parameters
y float: The visual y position of this view, in pixels.

setZ

Added in API level 21
void setZ (float z)

Sets the visual z position of this view, in pixels. This is equivalent to setting the translationZ property to be the difference between the x value passed in and the current elevation property.

Parameters
z float: The visual z position of this view, in pixels.

showContextMenu

Added in API level 1
boolean showContextMenu ()

Shows the context menu for this view.

Returns
boolean true if the context menu was shown, false otherwise

See also:

showContextMenu

Added in API level 24
boolean showContextMenu (float x, 
                float y)

Shows the context menu for this view anchored to the specified view-relative coordinate.

Parameters
x float: the X coordinate in pixels relative to the view to which the menu should be anchored, or NaN to disable anchoring
y float: the Y coordinate in pixels relative to the view to which the menu should be anchored, or NaN to disable anchoring
Returns
boolean true if the context menu was shown, false otherwise

startActionMode

Added in API level 23
ActionMode startActionMode (ActionMode.Callback callback, 
                int type)

Start an action mode with the given type.

Parameters
callback ActionMode.Callback: Callback that will control the lifecycle of the action mode
type int: One of TYPE_PRIMARY or TYPE_FLOATING.
Returns
ActionMode The new action mode if it is started, null otherwise

See also:

startActionMode

Added in API level 11
ActionMode startActionMode (ActionMode.Callback callback)

Start an action mode with the default type TYPE_PRIMARY.

Parameters
callback ActionMode.Callback: Callback that will control the lifecycle of the action mode
Returns
ActionMode The new action mode if it is started, null otherwise

See also:

startAnimation

Added in API level 1
void startAnimation (Animation animation)

Start the specified animation now.

Parameters
animation Animation: the animation to start now

startDrag

Added in API level 11
boolean startDrag (ClipData data, 
                View.DragShadowBuilder shadowBuilder, 
                Object myLocalState, 
                int flags)

This method was deprecated in API level 24.
Use startDragAndDrop() for newer platform versions.

Parameters
data ClipData
shadowBuilder View.DragShadowBuilder
myLocalState Object
flags int
Returns
boolean

startDragAndDrop

Added in API level 24
boolean startDragAndDrop (ClipData data, 
                View.DragShadowBuilder shadowBuilder, 
                Object myLocalState, 
                int flags)

Starts a drag and drop operation. When your application calls this method, it passes a View.DragShadowBuilder object to the system. The system calls this object's onProvideShadowMetrics(Point, Point) to get metrics for the drag shadow, and then calls the object's onDrawShadow(Canvas) to draw the drag shadow itself.

Once the system has the drag shadow, it begins the drag and drop operation by sending drag events to all the View objects in your application that are currently visible. It does this either by calling the View object's drag listener (an implementation of onDrag() or by calling the View object's onDragEvent() method. Both are passed a DragEvent object that has a getAction() value of ACTION_DRAG_STARTED.

Your application can invoke startDragAndDrop() on any attached View object. The View object does not need to be the one used in View.DragShadowBuilder, nor does it need to be related to the View the user selected for dragging.

Parameters
data ClipData: A ClipData object pointing to the data to be transferred by the drag and drop operation.
shadowBuilder View.DragShadowBuilder: A View.DragShadowBuilder object for building the drag shadow.
myLocalState Object: An Object containing local data about the drag and drop operation. This Object is put into every DragEvent object sent by the system during the current drag.

myLocalState is a lightweight mechanism for the sending information from the dragged View to the target Views. For example, it can contain flags that differentiate between a a copy operation and a move operation.

flags int: Flags that control the drag and drop operation. This can be set to 0 for no flags, or any combination of the following:
Returns
boolean true if the method completes successfully, or false if it fails anywhere. Returning false means the system was unable to do a drag, and so no drag operation is in progress.

startNestedScroll

Added in API level 21
boolean startNestedScroll (int axes)

Begin a nestable scroll operation along the given axes.

A view starting a nested scroll promises to abide by the following contract:

The view will call startNestedScroll upon initiating a scroll operation. In the case of a touch scroll this corresponds to the initial ACTION_DOWN. In the case of touch scrolling the nested scroll will be terminated automatically in the same manner as requestDisallowInterceptTouchEvent(boolean). In the event of programmatic scrolling the caller must explicitly call stopNestedScroll() to indicate the end of the nested scroll.

If startNestedScroll returns true, a cooperative parent was found. If it returns false the caller may ignore the rest of this contract until the next scroll. Calling startNestedScroll while a nested scroll is already in progress will return true.

At each incremental step of the scroll the caller should invoke dispatchNestedPreScroll once it has calculated the requested scrolling delta. If it returns true the nested scrolling parent at least partially consumed the scroll and the caller should adjust the amount it scrolls by.

After applying the remainder of the scroll delta the caller should invoke dispatchNestedScroll, passing both the delta consumed and the delta unconsumed. A nested scrolling parent may treat these values differently. See onNestedScroll(View, int, int, int, int).

Parameters
axes int: Flags consisting of a combination of SCROLL_AXIS_HORIZONTAL and/or SCROLL_AXIS_VERTICAL.
Returns
boolean true if a cooperative parent was found and nested scrolling has been enabled for the current gesture.

See also:

stopNestedScroll

Added in API level 21
void stopNestedScroll ()

Stop a nested scroll in progress.

Calling this method when a nested scroll is not currently in progress is harmless.

See also:

toString

Added in API level 1
String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
String a string representation of the object.

unscheduleDrawable

Added in API level 1
void unscheduleDrawable (Drawable who, 
                Runnable what)

Cancels a scheduled action on a drawable.

Parameters
who Drawable: the recipient of the action
what Runnable: the action to cancel

unscheduleDrawable

Added in API level 1
void unscheduleDrawable (Drawable who)

Unschedule any events associated with the given Drawable. This can be used when selecting a new Drawable into a view, so that the previous one is completely unscheduled.

Parameters
who Drawable: The Drawable to unschedule.

See also:

updateDragShadow

Added in API level 24
void updateDragShadow (View.DragShadowBuilder shadowBuilder)

Updates the drag shadow for the ongoing drag and drop operation.

Parameters
shadowBuilder View.DragShadowBuilder: A View.DragShadowBuilder object for building the new drag shadow.

willNotCacheDrawing

Added in API level 1
boolean willNotCacheDrawing ()

Returns whether or not this View can cache its drawing or not.

Returns
boolean true if this view does not cache its drawing, false otherwise

willNotDraw

Added in API level 1
boolean willNotDraw ()

Returns whether or not this View draws on its own.

Returns
boolean true if this view has nothing to draw, false otherwise

Protected methods

awakenScrollBars

Added in API level 5
boolean awakenScrollBars (int startDelay, 
                boolean invalidate)

Trigger the scrollbars to draw. When invoked this method starts an animation to fade the scrollbars out after a fixed delay. If a subclass provides animated scrolling, the start delay should equal the duration of the scrolling animation.

The animation starts only if at least one of the scrollbars is enabled, as specified by isHorizontalScrollBarEnabled() and isVerticalScrollBarEnabled(). When the animation is started, this method returns true, and false otherwise. If the animation is started, this method calls invalidate() if the invalidate parameter is set to true; in that case the caller should not call invalidate().

This method should be invoked every time a subclass directly updates the scroll parameters.

Parameters
startDelay int: the delay, in milliseconds, after which the animation should start; when the delay is 0, the animation starts immediately
invalidate boolean: Whether this method should call invalidate
Returns
boolean true if the animation is played, false otherwise

See also:

awakenScrollBars

Added in API level 5
boolean awakenScrollBars (int startDelay)

Trigger the scrollbars to draw. When invoked this method starts an animation to fade the scrollbars out after a fixed delay. If a subclass provides animated scrolling, the start delay should equal the duration of the scrolling animation.

The animation starts only if at least one of the scrollbars is enabled, as specified by isHorizontalScrollBarEnabled() and isVerticalScrollBarEnabled(). When the animation is started, this method returns true, and false otherwise. If the animation is started, this method calls invalidate(); in that case the caller should not call invalidate().

This method should be invoked every time a subclass directly updates the scroll parameters.

Parameters
startDelay int: the delay, in milliseconds, after which the animation should start; when the delay is 0, the animation starts immediately
Returns
boolean true if the animation is played, false otherwise

See also:

awakenScrollBars

Added in API level 5
boolean awakenScrollBars ()

Trigger the scrollbars to draw. When invoked this method starts an animation to fade the scrollbars out after a default delay. If a subclass provides animated scrolling, the start delay should equal the duration of the scrolling animation.

The animation starts only if at least one of the scrollbars is enabled, as specified by isHorizontalScrollBarEnabled() and isVerticalScrollBarEnabled(). When the animation is started, this method returns true, and false otherwise. If the animation is started, this method calls invalidate(); in that case the caller should not call invalidate().

This method should be invoked every time a subclass directly updates the scroll parameters.

This method is automatically invoked by scrollBy(int, int) and scrollTo(int, int).

Returns
boolean true if the animation is played, false otherwise

See also:

computeHorizontalScrollExtent

Added in API level 1
int computeHorizontalScrollExtent ()

Compute the horizontal extent of the horizontal scrollbar's thumb within the horizontal range. This value is used to compute the length of the thumb within the scrollbar's track.

The range is expressed in arbitrary units that must be the same as the units used by computeHorizontalScrollRange() and computeHorizontalScrollOffset().

The default extent is the drawing width of this view.

Returns
int the horizontal extent of the scrollbar's thumb

See also:

computeHorizontalScrollOffset

Added in API level 1
int computeHorizontalScrollOffset ()

Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range. This value is used to compute the position of the thumb within the scrollbar's track.

The range is expressed in arbitrary units that must be the same as the units used by computeHorizontalScrollRange() and computeHorizontalScrollExtent().

The default offset is the scroll offset of this view.

Returns
int the horizontal offset of the scrollbar's thumb

See also:

computeHorizontalScrollRange

Added in API level 1
int computeHorizontalScrollRange ()

Compute the horizontal range that the horizontal scrollbar represents.

The range is expressed in arbitrary units that must be the same as the units used by computeHorizontalScrollExtent() and computeHorizontalScrollOffset().

The default range is the drawing width of this view.

Returns
int the total horizontal range represented by the horizontal scrollbar

See also:

computeVerticalScrollExtent

Added in API level 1
int computeVerticalScrollExtent ()

Compute the vertical extent of the vertical scrollbar's thumb within the vertical range. This value is used to compute the length of the thumb within the scrollbar's track.

The range is expressed in arbitrary units that must be the same as the units used by computeVerticalScrollRange() and computeVerticalScrollOffset().

The default extent is the drawing height of this view.

Returns
int the vertical extent of the scrollbar's thumb

See also:

computeVerticalScrollOffset

Added in API level 1
int computeVerticalScrollOffset ()

Compute the vertical offset of the vertical scrollbar's thumb within the horizontal range. This value is used to compute the position of the thumb within the scrollbar's track.

The range is expressed in arbitrary units that must be the same as the units used by computeVerticalScrollRange() and computeVerticalScrollExtent().

The default offset is the scroll offset of this view.

Returns
int the vertical offset of the scrollbar's thumb

See also:

computeVerticalScrollRange

Added in API level 1
int computeVerticalScrollRange ()

Compute the vertical range that the vertical scrollbar represents.

The range is expressed in arbitrary units that must be the same as the units used by computeVerticalScrollExtent() and computeVerticalScrollOffset().

Returns
int the total vertical range represented by the vertical scrollbar

The default range is the drawing height of this view.

See also:

dispatchDraw

Added in API level 1
void dispatchDraw (Canvas canvas)

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: the canvas on which to draw the view

dispatchGenericFocusedEvent

Added in API level 14
boolean dispatchGenericFocusedEvent (MotionEvent event)

Dispatch a generic motion event to the currently focused view.

Do not call this method directly. Call dispatchGenericMotionEvent(MotionEvent) instead.

Parameters
event MotionEvent: The motion event to be dispatched.
Returns
boolean True if the event was handled by the view, false otherwise.

dispatchGenericPointerEvent

Added in API level 14
boolean dispatchGenericPointerEvent (MotionEvent event)

Dispatch a generic motion event to the view under the first pointer.

Do not call this method directly. Call dispatchGenericMotionEvent(MotionEvent) instead.

Parameters
event MotionEvent: The motion event to be dispatched.
Returns
boolean True if the event was handled by the view, false otherwise.

dispatchHoverEvent

Added in API level 14
boolean dispatchHoverEvent (MotionEvent event)

Dispatch a hover event.

Do not call this method directly. Call dispatchGenericMotionEvent(MotionEvent) instead.

Parameters
event MotionEvent: The motion event to be dispatched.
Returns
boolean True if the event was handled by the view, false otherwise.

dispatchRestoreInstanceState

Added in API level 1
void dispatchRestoreInstanceState (SparseArray<Parcelable> container)

Called by restoreHierarchyState(android.util.SparseArray) to retrieve the state for this view and its children. May be overridden to modify how restoring happens to a view's children; for example, some views may want to not store state for their children.

Parameters
container SparseArray: The SparseArray which holds previously saved state.

See also:

dispatchSaveInstanceState

Added in API level 1
void dispatchSaveInstanceState (SparseArray<Parcelable> container)

Called by saveHierarchyState(android.util.SparseArray) to store the state for this view and its children. May be overridden to modify how freezing happens to a view's children; for example, some views may want to not store state for their children.

Parameters
container SparseArray: The SparseArray in which to save the view's state.

See also:

dispatchSetActivated

Added in API level 11
void dispatchSetActivated (boolean activated)

Dispatch setActivated to all of this View's children.

Parameters
activated boolean: The new activated state

See also:

dispatchSetPressed

Added in API level 1
void dispatchSetPressed (boolean pressed)

Dispatch setPressed to all of this View's children.

Parameters
pressed boolean: The new pressed state

See also:

dispatchSetSelected

Added in API level 1
void dispatchSetSelected (boolean selected)

Dispatch setSelected to all of this View's children.

Parameters
selected boolean: The new selected state

See also:

dispatchVisibilityChanged

Added in API level 8
void dispatchVisibilityChanged (View changedView, 
                int visibility)

Dispatch a view visibility change down the view hierarchy. ViewGroups should override to route to their children.

Parameters
changedView View: The view whose visibility changed. Could be 'this' or an ancestor view.
visibility int: The new visibility of changedView: VISIBLE, INVISIBLE or GONE.

drawableStateChanged

Added in API level 1
void drawableStateChanged ()

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

If the View has a StateListAnimator, it will also be called to run necessary state change animations.

Be sure to call through to the superclass when overriding this function.

See also:

fitSystemWindows

Added in API level 1
boolean fitSystemWindows (Rect insets)

This method was deprecated in API level 20.
As of API 20 use dispatchApplyWindowInsets(WindowInsets) to apply insets to views. Views should override onApplyWindowInsets(WindowInsets) or use setOnApplyWindowInsetsListener(android.view.View.OnApplyWindowInsetsListener) to implement handling their own insets.

Called by the view hierarchy when the content insets for a window have changed, to allow it to adjust its content to fit within those windows. The content insets tell you the space that the status bar, input method, and other system windows infringe on the application's window.

You do not normally need to deal with this function, since the default window decoration given to applications takes care of applying it to the content of the window. If you use SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION this will not be the case, and your content can be placed under those system elements. You can then use this method within your view hierarchy if you have parts of your UI which you would like to ensure are not being covered.

The default implementation of this method simply applies the content insets to the view's padding, consuming that content (modifying the insets to be 0), and returning true. This behavior is off by default, but can be enabled through setFitsSystemWindows(boolean).

This function's traversal down the hierarchy is depth-first. The same content insets object is propagated down the hierarchy, so any changes made to it will be seen by all following views (including potentially ones above in the hierarchy since this is a depth-first traversal). The first view that returns true will abort the entire traversal.

The default implementation works well for a situation where it is used with a container that covers the entire window, allowing it to apply the appropriate insets to its content on all edges. If you need a more complicated layout (such as two different views fitting system windows, one on the top of the window, and one on the bottom), you can override the method and handle the insets however you would like. Note that the insets provided by the framework are always relative to the far edges of the window, not accounting for the location of the called view within that window. (In fact when this method is called you do not yet know where the layout will place the view, as it is done before layout happens.)

Note: unlike many View methods, there is no dispatch phase to this call. If you are overriding it in a ViewGroup and want to allow the call to continue to your children, you must be sure to call the super implementation.

Here is a sample layout that makes use of fitting system windows to have controls for a video view placed inside of the window decorations that it hides and shows. This can be used with code like the second sample (video player) shown in setSystemUiVisibility(int).

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    >
    <view class="com.example.android.apis.view.VideoPlayerActivity$Content"
        android:id="@+id/content"
        android:src="@drawable/frantic"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="center"
        />
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:animateLayoutChanges="true"
        >
        <TextView
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top|center_horizontal"
            android:textColor="#ffffffff"
            android:background="#a0000000"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:gravity="left"
            android:padding="16dp"
            android:text="A title goes here"
            />
        <Button
            android:id="@+id/play"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:textSize="28dp"
            />
        <SeekBar
            android:id="@+id/seekbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:layout_marginBottom="16dp"
            />
    </FrameLayout>
</FrameLayout>

Parameters
insets Rect: Current content insets of the window. Prior to JELLY_BEAN you must not modify the insets or else you and Android will be unhappy.
Returns
boolean true if this view applied the insets and it should not continue propagating further down the hierarchy, false otherwise.

See also:

getBottomFadingEdgeStrength

Added in API level 1
float getBottomFadingEdgeStrength ()

Returns the strength, or intensity, of the bottom faded edge. The strength is a value between 0.0 (no fade) and 1.0 (full fade). The default implementation returns 0.0 or 1.0 but no value in between. Subclasses should override this method to provide a smoother fade transition when scrolling occurs.

Returns
float the intensity of the bottom fade as a float between 0.0f and 1.0f

getBottomPaddingOffset

Added in API level 2
int getBottomPaddingOffset ()

Amount by which to extend the bottom fading region. Called only when isPaddingOffsetRequired() returns true.

Returns
int The bottom padding offset in pixels.

See also:

getContextMenuInfo

Added in API level 1
ContextMenu.ContextMenuInfo getContextMenuInfo ()

Views should implement this if they have extra information to associate with the context menu. The return result is supplied as a parameter to the onCreateContextMenu(ContextMenu, View, ContextMenuInfo) callback.

Returns
ContextMenu.ContextMenuInfo Extra information about the item for which the context menu should be shown. This information will vary across different subclasses of View.

getHorizontalScrollbarHeight

Added in API level 1
int getHorizontalScrollbarHeight ()

Returns the height of the horizontal scrollbar.

Returns
int The height in pixels of the horizontal scrollbar or 0 if there is no horizontal scrollbar.

getLeftFadingEdgeStrength

Added in API level 1
float getLeftFadingEdgeStrength ()

Returns the strength, or intensity, of the left faded edge. The strength is a value between 0.0 (no fade) and 1.0 (full fade). The default implementation returns 0.0 or 1.0 but no value in between. Subclasses should override this method to provide a smoother fade transition when scrolling occurs.

Returns
float the intensity of the left fade as a float between 0.0f and 1.0f

getLeftPaddingOffset

Added in API level 2
int getLeftPaddingOffset ()

Amount by which to extend the left fading region. Called only when isPaddingOffsetRequired() returns true.

Returns
int The left padding offset in pixels.

See also:

getRightFadingEdgeStrength

Added in API level 1
float getRightFadingEdgeStrength ()

Returns the strength, or intensity, of the right faded edge. The strength is a value between 0.0 (no fade) and 1.0 (full fade). The default implementation returns 0.0 or 1.0 but no value in between. Subclasses should override this method to provide a smoother fade transition when scrolling occurs.

Returns
float the intensity of the right fade as a float between 0.0f and 1.0f

getRightPaddingOffset

Added in API level 2
int getRightPaddingOffset ()

Amount by which to extend the right fading region. Called only when isPaddingOffsetRequired() returns true.

Returns
int The right padding offset in pixels.

See also:

getSuggestedMinimumHeight

Added in API level 1
int getSuggestedMinimumHeight ()

Returns the suggested minimum height that the view should use. This returns the maximum of the view's minimum height and the background's minimum height (getMinimumHeight()).

When being used in onMeasure(int, int), the caller should still ensure the returned height is within the requirements of the parent.

Returns
int The suggested minimum height of the view.

getSuggestedMinimumWidth

Added in API level 1
int getSuggestedMinimumWidth ()

Returns the suggested minimum width that the view should use. This returns the maximum of the view's minimum width and the background's minimum width (getMinimumWidth()).

When being used in onMeasure(int, int), the caller should still ensure the returned width is within the requirements of the parent.

Returns
int The suggested minimum width of the view.

getTopFadingEdgeStrength

Added in API level 1
float getTopFadingEdgeStrength ()

Returns the strength, or intensity, of the top faded edge. The strength is a value between 0.0 (no fade) and 1.0 (full fade). The default implementation returns 0.0 or 1.0 but no value in between. Subclasses should override this method to provide a smoother fade transition when scrolling occurs.

Returns
float the intensity of the top fade as a float between 0.0f and 1.0f

getTopPaddingOffset

Added in API level 2
int getTopPaddingOffset ()

Amount by which to extend the top fading region. Called only when isPaddingOffsetRequired() returns true.

Returns
int The top padding offset in pixels.

See also:

getWindowAttachCount

Added in API level 1
int getWindowAttachCount ()

Returns
int The number of times this view has been attached to a window

isPaddingOffsetRequired

Added in API level 2
boolean isPaddingOffsetRequired ()

If the View draws content inside its padding and enables fading edges, it needs to support padding offsets. Padding offsets are added to the fading edges to extend the length of the fade so that it covers pixels drawn inside the padding. Subclasses of this class should override this method if they need to draw content inside the padding.

Returns
boolean True if padding offset must be applied, false otherwise.

See also:

mergeDrawableStates

Added in API level 1
int[] mergeDrawableStates (int[] baseState, 
                int[] additionalState)

Merge your own state values in additionalState into the base state values baseState that were returned by onCreateDrawableState(int).

Parameters
baseState int: The base state values returned by onCreateDrawableState(int), which will be modified to also hold your own additional state values.
additionalState int: The additional state values you would like added to baseState; this array is not modified.
Returns
int[] As a convenience, the baseState array you originally passed into the function is returned.

See also:

onAnimationEnd

Added in API level 1
void onAnimationEnd ()

Invoked by a parent ViewGroup to notify the end of the animation currently associated with this view. If you override this method, always call super.onAnimationEnd();

See also:

onAnimationStart

Added in API level 1
void onAnimationStart ()

Invoked by a parent ViewGroup to notify the start of the animation currently associated with this view. If you override this method, always call super.onAnimationStart();

See also:

onAttachedToWindow

Added in API level 1
void onAttachedToWindow ()

This is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(android.graphics.Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int, int).

See also:

onConfigurationChanged

Added in API level 8
void onConfigurationChanged (Configuration newConfig)

Called when the current configuration of the resources being used by the application have changed. You can use this to decide when to reload resources that can changed based on orientation and other configuration characteristics. You only need to use this if you are not relying on the normal Activity mechanism of recreating the activity instance upon a configuration change.

Parameters
newConfig Configuration: The new resource configuration.

onCreateContextMenu

Added in API level 1
void onCreateContextMenu (ContextMenu menu)

Views should implement this if the view itself is going to add items to the context menu.

Parameters
menu ContextMenu: the context menu to populate

onCreateDrawableState

Added in API level 1
int[] onCreateDrawableState (int extraSpace)

Generate the new Drawable state for this view. This is called by the view system when the cached Drawable state is determined to be invalid. To retrieve the current state, you should use getDrawableState().

Parameters
extraSpace int: if non-zero, this is the number of extra entries you would like in the returned array in which you can place your own states.
Returns
int[] Returns an array holding the current Drawable state of the view.

See also:

onDetachedFromWindow

Added in API level 1
void onDetachedFromWindow ()

This is called when the view is detached from a window. At this point it no longer has a surface for drawing.

See also:

onDisplayHint

Added in API level 8
void onDisplayHint (int hint)

Gives this view a hint about whether is displayed or not. For instance, when a View moves out of the screen, it might receives a display hint indicating the view is not displayed. Applications should not rely on this hint as there is no guarantee that they will receive one.

Parameters
hint int: A hint about whether or not this view is displayed: VISIBLE or INVISIBLE.

onDraw

Added in API level 1
void onDraw (Canvas canvas)

Implement this to do your drawing.

Parameters
canvas Canvas: the canvas on which the background will be drawn

onDrawScrollBars

Added in API level 7
void onDrawScrollBars (Canvas canvas)

Request the drawing of the horizontal and the vertical scrollbar. The scrollbars are painted only if they have been awakened first.

Parameters
canvas Canvas: the canvas on which to draw the scrollbars

See also:

onFinishInflate

Added in API level 1
void onFinishInflate ()

Finalize inflating a view from XML. This is called as the last phase of inflation, after all child views have been added.

Even if the subclass overrides onFinishInflate, they should always be sure to call the super method, so that we get called.

onFocusChanged

Added in API level 1
void onFocusChanged (boolean gainFocus, 
                int direction, 
                Rect previouslyFocusedRect)

Called by the view system when the focus state of this view changes. When the focus change event is caused by directional navigation, direction and previouslyFocusedRect provide insight into where the focus is coming from. When overriding, be sure to call up through to the super class so that the standard focus handling will occur.

Parameters
gainFocus boolean: True if the View has focus; false otherwise.
direction int: The direction focus has moved when requestFocus() is called to give this view focus. Values are FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, or FOCUS_BACKWARD. It may not always apply, in which case use the default.
previouslyFocusedRect Rect: The rectangle, in this view's coordinate system, of the previously focused view. If applicable, this will be passed in as finer grained information about where the focus is coming from (in addition to direction). Will be null otherwise.

onLayout

Added in API level 1
void onLayout (boolean changed, 
                int left, 
                int top, 
                int right, 
                int bottom)

Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.

Parameters
changed boolean: This is a new size or position for this view
left int: Left position, relative to parent
top int: Top position, relative to parent
right int: Right position, relative to parent
bottom int: Bottom position, relative to parent

onMeasure

Added in API level 1
void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overridden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec int: horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec int: vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.

See also:

onOverScrolled

Added in API level 9
void onOverScrolled (int scrollX, 
                int scrollY, 
                boolean clampedX, 
                boolean clampedY)

Called by overScrollBy(int, int, int, int, int, int, int, int, boolean) to respond to the results of an over-scroll operation.

Parameters
scrollX int: New X scroll value in pixels
scrollY int: New Y scroll value in pixels
clampedX boolean: True if scrollX was clamped to an over-scroll boundary
clampedY boolean: True if scrollY was clamped to an over-scroll boundary

onRestoreInstanceState

Added in API level 1
void onRestoreInstanceState (Parcelable state)

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState(). This function will never be called with a null state.

Parameters
state Parcelable: The frozen state that had previously been returned by onSaveInstanceState().

See also:

onSaveInstanceState

Added in API level 1
Parcelable onSaveInstanceState ()

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can not be reconstructed later. For example, you will never store your current position on screen because that will be computed again when a new instance of the view is placed in its view hierarchy.

Some examples of things you may store here: the current cursor position in a text view (but usually not the text itself since that is stored in a content provider or other persistent storage), the currently selected item in a list view.

Returns
Parcelable Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save. The default implementation returns null.

See also:

onScrollChanged

Added in API level 1
void onScrollChanged (int l, 
                int t, 
                int oldl, 
                int oldt)

This is called in response to an internal scroll in this view (i.e., the view scrolled its own contents). This is typically as a result of scrollBy(int, int) or scrollTo(int, int) having been called.

Parameters
l int: Current horizontal scroll origin.
t int: Current vertical scroll origin.
oldl int: Previous horizontal scroll origin.
oldt int: Previous vertical scroll origin.

onSetAlpha

Added in API level 1
boolean onSetAlpha (int alpha)

Invoked if there is a Transform that involves alpha. Subclass that can draw themselves with the specified alpha should return true, and then respect that alpha when their onDraw() is called. If this returns false then the view may be redirected to draw into an offscreen buffer to fulfill the request, which will look fine, but may be slower than if the subclass handles it internally. The default implementation returns false.

Parameters
alpha int: The alpha (0..255) to apply to the view's drawing
Returns
boolean true if the view can draw with the specified alpha.

onSizeChanged

Added in API level 1
void onSizeChanged (int w, 
                int h, 
                int oldw, 
                int oldh)

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.

onVisibilityChanged

Added in API level 8
void onVisibilityChanged (View changedView, 
                int visibility)

Called when the visibility of the view or an ancestor of the view has changed.

Parameters
changedView View: The view whose visibility changed. May be this or an ancestor view.
visibility int: The new visibility, one of VISIBLE, INVISIBLE or GONE.

onWindowVisibilityChanged

Added in API level 1
void onWindowVisibilityChanged (int visibility)

Called when the window containing has change its visibility (between GONE, INVISIBLE, and VISIBLE). Note that this tells you whether or not your window is being made visible to the window manager; this does not tell you whether or not your window is obscured by other windows on the screen, even if it is itself visible.

Parameters
visibility int: The new visibility of the window.

overScrollBy

Added in API level 9
boolean overScrollBy (int deltaX, 
                int deltaY, 
                int scrollX, 
                int scrollY, 
                int scrollRangeX, 
                int scrollRangeY, 
                int maxOverScrollX, 
                int maxOverScrollY, 
                boolean isTouchEvent)

Scroll the view with standard behavior for scrolling beyond the normal content boundaries. Views that call this method should override onOverScrolled(int, int, boolean, boolean) to respond to the results of an over-scroll operation. Views can use this method to handle any touch or fling-based scrolling.

Parameters
deltaX int: Change in X in pixels
deltaY int: Change in Y in pixels
scrollX int: Current X scroll value in pixels before applying deltaX
scrollY int: Current Y scroll value in pixels before applying deltaY
scrollRangeX int: Maximum content scroll range along the X axis
scrollRangeY int: Maximum content scroll range along the Y axis
maxOverScrollX int: Number of pixels to overscroll by in either direction along the X axis.
maxOverScrollY int: Number of pixels to overscroll by in either direction along the Y axis.
isTouchEvent boolean: true if this scroll operation is the result of a touch event.
Returns
boolean true if scrolling was clamped to an over-scroll boundary along either axis, false otherwise.

setMeasuredDimension

Added in API level 1
void setMeasuredDimension (int measuredWidth, 
                int measuredHeight)

This method must be called by onMeasure(int, int) to store the measured width and measured height. Failing to do so will trigger an exception at measurement time.

Parameters
measuredWidth int: The measured width of this view. May be a complex bit mask as defined by MEASURED_SIZE_MASK and MEASURED_STATE_TOO_SMALL.
measuredHeight int: The measured height of this view. May be a complex bit mask as defined by MEASURED_SIZE_MASK and MEASURED_STATE_TOO_SMALL.

verifyDrawable

Added in API level 1
boolean verifyDrawable (Drawable who)

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying. This allows animations for those drawables to be scheduled.

Be sure to call through to the super class when overriding this function.

Parameters
who Drawable: The Drawable to verify. Return true if it is one you are displaying, else return the result of calling through to the super class.
Returns
boolean boolean If true than the Drawable is being displayed in the view; else false and it is not allowed to animate.

See also:

Hooray!