Google 致力于为黑人社区推动种族平等。查看具体举措

ViewCompat

public class ViewCompat
extends Object

java.lang.Object
   ↳ androidx.core.view.ViewCompat


Helper for accessing features in View.

Summary

Nested classes

interface ViewCompat.OnUnhandledKeyEventListenerCompat

Interface definition for a callback to be invoked when a hardware key event hasn't been handled by the view hierarchy. 

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 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 LAYER_TYPE_HARDWARE

This constant is deprecated. Use View.LAYER_TYPE_HARDWARE directly.

int LAYER_TYPE_NONE

This constant is deprecated. Use View.LAYER_TYPE_NONE directly.

int LAYER_TYPE_SOFTWARE

This constant is deprecated. Use View.LAYER_TYPE_SOFTWARE directly.

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

This constant is deprecated. Use View.MEASURED_HEIGHT_STATE_SHIFT directly.

int MEASURED_SIZE_MASK

This constant is deprecated. Use View.MEASURED_SIZE_MASK directly.

int MEASURED_STATE_MASK

This constant is deprecated. Use View.MEASURED_STATE_MASK directly.

int MEASURED_STATE_TOO_SMALL

This constant is deprecated. Use View.MEASURED_STATE_TOO_SMALL directly.

int OVER_SCROLL_ALWAYS

This constant is deprecated. Use View.OVER_SCROLL_ALWAYS directly. This constant will be removed in a future release.

int OVER_SCROLL_IF_CONTENT_SCROLLS

This constant is deprecated. Use View.OVER_SCROLL_IF_CONTENT_SCROLLS directly. This constant will be removed in a future release.

int OVER_SCROLL_NEVER

This constant is deprecated. Use View.OVER_SCROLL_NEVER directly. This constant will be removed in a future release.

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 TYPE_NON_TOUCH

Indicates that the input type for the gesture is caused by something which is not a user touching a screen.

int TYPE_TOUCH

Indicates that the input type for the gesture is from a user touching the screen.

Protected constructors

ViewCompat()

This constructor is deprecated. This is a utility class and it shouldn't be instantiated.

Public methods

static int addAccessibilityAction(View view, CharSequence label, AccessibilityViewCommand command)

Adds an accessibility action that can be performed on a node associated with a view.

static void addKeyboardNavigationClusters(View view, Collection<View> views, int direction)

Adds any keyboard navigation cluster roots that are descendants of view ( including view if it is a cluster root itself) to views.

static void addOnUnhandledKeyEventListener(View v, ViewCompat.OnUnhandledKeyEventListenerCompat listener)

Adds a listener which will receive unhandled KeyEvents.

static ViewPropertyAnimatorCompat animate(View view)

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

static boolean canScrollHorizontally(View view, int direction)

This method is deprecated. Use View.canScrollHorizontally(int) directly.

static boolean canScrollVertically(View view, int direction)

This method is deprecated. Use View.canScrollVertically(int) directly.

static void cancelDragAndDrop(View v)

Cancel the drag and drop operation.

static int combineMeasuredStates(int curState, int newState)

This method is deprecated. Use View.combineMeasuredStates(int, int) directly.

static WindowInsetsCompat computeSystemWindowInsets(View view, WindowInsetsCompat insets, Rect outLocalInsets)

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

static WindowInsetsCompat dispatchApplyWindowInsets(View view, WindowInsetsCompat insets)

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

static void dispatchFinishTemporaryDetach(View view)

Notify a view that its temporary detach has ended; the view is now reattached.

static boolean dispatchNestedFling(View view, float velocityX, float velocityY, boolean consumed)

Dispatch a fling to a nested scrolling parent.

static boolean dispatchNestedPreFling(View view, float velocityX, float velocityY)

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

static boolean dispatchNestedPreScroll(View view, int dx, int dy, int[] consumed, int[] offsetInWindow, int type)

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

static boolean dispatchNestedPreScroll(View view, 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.

static boolean dispatchNestedScroll(View view, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow, int type)

Dispatch one step of a nested scroll in progress.

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

Dispatch one step of a nested scroll in progress.

static void dispatchNestedScroll(View view, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow, int type, int[] consumed)

Dispatch one step of a nested scroll in progress.

static void dispatchStartTemporaryDetach(View view)

Notify a view that it is being temporarily detached.

static void enableAccessibleClickableSpanSupport(View view)

Allow accessibility services to find and activate clickable spans in the application.

static int generateViewId()

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

static AccessibilityDelegateCompat getAccessibilityDelegate(View view)

Get the current accessibility delegate.

static int getAccessibilityLiveRegion(View view)

Gets the live region mode for the specified View.

static AccessibilityNodeProviderCompat getAccessibilityNodeProvider(View view)

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

static CharSequence getAccessibilityPaneTitle(View view)

Get the title of the pane for purposes of accessibility.

static float getAlpha(View view)

This method is deprecated. Use View.getAlpha() directly.

static ColorStateList getBackgroundTintList(View view)

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

static PorterDuff.Mode getBackgroundTintMode(View view)

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

static Rect getClipBounds(View view)

Returns a copy of the current setClipBounds(View, Rect).

static Display getDisplay(View view)

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

static float getElevation(View view)

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

static boolean getFitsSystemWindows(View v)

Returns true if this view should adapt to fit system window insets.

static int getImportantForAccessibility(View view)

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.

static int getImportantForAutofill(View v)

Gets the mode for determining whether this view is important for autofill.

static int getLabelFor(View view)

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

static int getLayerType(View view)

This method is deprecated. Use View.getLayerType() directly.

static int getLayoutDirection(View view)

Returns the resolved layout direction for this view.

static Matrix getMatrix(View view)

This method is deprecated. Use View.getMatrix() directly.

static int getMeasuredHeightAndState(View view)

This method is deprecated. Use View.getMeasuredHeightAndState() directly.

static int getMeasuredState(View view)

This method is deprecated. Use View.getMeasuredState() directly.

static int getMeasuredWidthAndState(View view)

This method is deprecated. Use View.getMeasuredWidth() directly.

static int getMinimumHeight(View view)

Returns the minimum height of the view.

static int getMinimumWidth(View view)

Returns the minimum width of the view.

static int getNextClusterForwardId(View view)

Gets the ID of the next keyboard navigation cluster root.

static String[] getOnReceiveContentMimeTypes(View view)

Returns the MIME types accepted by the listener configured on the given view via setOnReceiveContentListener(View, String[], OnReceiveContentListener).

static int getOverScrollMode(View v)

This method is deprecated. Call View.getOverScrollMode() directly. This method will be removed in a future release.

static int getPaddingEnd(View view)

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

static int getPaddingStart(View view)

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

static ViewParent getParentForAccessibility(View view)

Gets the parent for accessibility purposes.

static float getPivotX(View view)

This method is deprecated. Use View.getPivotX() directly.

static float getPivotY(View view)

This method is deprecated. Use View.getPivotY() directly.

static WindowInsetsCompat getRootWindowInsets(View view)

Provide original WindowInsetsCompat that are dispatched to the view hierarchy.

static float getRotation(View view)

This method is deprecated. Use View.getRotation() directly.

static float getRotationX(View view)

This method is deprecated. Use View.getRotationX() directly.

static float getRotationY(View view)

This method is deprecated. Use View.getRotationY() directly.

static float getScaleX(View view)

This method is deprecated. Use View.getScaleX() directly.

static float getScaleY(View view)

This method is deprecated. Use View.getScaleY() directly.

static int getScrollIndicators(View view)

Returns a bitmask representing the enabled scroll indicators.

static final CharSequence getStateDescription(View view)

Returns the View's state description.

static List<Rect> getSystemGestureExclusionRects(View view)

Retrieve the list of areas within this view's post-layout coordinate space where the system should not intercept touch or other pointing device gestures.

static String getTransitionName(View view)

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

static float getTranslationX(View view)

This method is deprecated. Use View.getTranslationX() directly.

static float getTranslationY(View view)

This method is deprecated. Use View.getTranslationY() directly.

static float getTranslationZ(View view)

The depth location of this view relative to its elevation.

static WindowInsetsControllerCompat getWindowInsetsController(View view)

Retrieves a WindowInsetsControllerCompat of the window this view is attached to.

static int getWindowSystemUiVisibility(View view)

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

static float getX(View view)

This method is deprecated. Use View.getX() directly.

static float getY(View view)

This method is deprecated. Use View.getY() directly.

static float getZ(View view)

The visual z position of this view, in pixels.

static boolean hasAccessibilityDelegate(View view)

Checks whether provided View has an accessibility delegate attached to it.

static boolean hasExplicitFocusable(View view)

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

static boolean hasNestedScrollingParent(View view, int type)

Returns true if this view has a nested scrolling parent.

static boolean hasNestedScrollingParent(View view)

Returns true if this view has a nested scrolling parent.

static boolean hasOnClickListeners(View view)

Returns whether the provided view has an attached View.OnClickListener.

static boolean hasOverlappingRendering(View view)

Returns whether this View has content which overlaps.

static boolean hasTransientState(View view)

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.

static boolean isAccessibilityHeading(View view)

Gets whether this view is a heading for accessibility purposes.

static boolean isAttachedToWindow(View view)

Returns true if the provided view is currently attached to a window.

static boolean isFocusedByDefault(View view)

Returns whether view should receive focus when the focus is restored for the view hierarchy containing it.

static boolean isImportantForAccessibility(View view)

Computes whether this view should be exposed for accessibility.

static boolean isImportantForAutofill(View v)

Hints the Android System whether the AssistStructure.ViewNode associated with this view is considered important for autofill purposes.

static boolean isInLayout(View view)

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

static boolean isKeyboardNavigationCluster(View view)

Returns whether view is a root of a keyboard navigation cluster.

static boolean isLaidOut(View view)

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

static boolean isLayoutDirectionResolved(View view)

Returns whether layout direction has been resolved.

static boolean isNestedScrollingEnabled(View view)

Returns true if nested scrolling is enabled for this view.

static boolean isOpaque(View view)

This method is deprecated. Use View.isOpaque() directly. This method will be removed in a future release.

static boolean isPaddingRelative(View view)

Return if the padding as been set through relative values View.setPaddingRelative(int, int, int, int) or thru

static boolean isScreenReaderFocusable(View view)

Returns whether the view should be treated as a focusable unit by screen reader accessibility tools.

static void jumpDrawablesToCurrentState(View v)

This method is deprecated. Use View.jumpDrawablesToCurrentState() directly.

static View keyboardNavigationClusterSearch(View view, View currentCluster, int direction)

Find the nearest keyboard navigation cluster in the specified direction.

static void offsetLeftAndRight(View view, int offset)

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

static void offsetTopAndBottom(View view, int offset)

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

static WindowInsetsCompat onApplyWindowInsets(View view, WindowInsetsCompat insets)

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

static void onInitializeAccessibilityEvent(View v, AccessibilityEvent event)

This method is deprecated. Call View.onInitializeAccessibilityEvent(AccessibilityEvent) directly. This method will be removed in a future release.

static void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfoCompat info)

Initializes an AccessibilityNodeInfoCompat with information about this view.

static void onPopulateAccessibilityEvent(View v, AccessibilityEvent event)

This method is deprecated. Call View.onPopulateAccessibilityEvent(AccessibilityEvent) directly. This method will be removed in a future release.

static boolean performAccessibilityAction(View view, int action, Bundle arguments)

Performs the specified accessibility action on the view.

static ContentInfoCompat performReceiveContent(View view, ContentInfoCompat payload)

Receives the given content.

static void postInvalidateOnAnimation(View view, 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.

static void postInvalidateOnAnimation(View view)

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

static void postOnAnimation(View view, Runnable action)

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

static void postOnAnimationDelayed(View view, Runnable action, long delayMillis)

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

static void removeAccessibilityAction(View view, int actionId)

Removes an accessibility action that can be performed on a node associated with a view.

static void removeOnUnhandledKeyEventListener(View v, ViewCompat.OnUnhandledKeyEventListenerCompat listener)

Removes a listener which will receive unhandled KeyEvents.

static void replaceAccessibilityAction(View view, AccessibilityNodeInfoCompat.AccessibilityActionCompat replacedAction, CharSequence label, AccessibilityViewCommand command)

Replaces an action.

static void requestApplyInsets(View view)

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

static <T extends View> T requireViewById(View view, int id)

Finds the first descendant view with the given ID, the view itself if the ID matches View.getId(), or throws an IllegalArgumentException if the ID is invalid or there is no matching view in the hierarchy.

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

This method is deprecated. Use View.resolveSizeAndState(int, int, int) directly.

static boolean restoreDefaultFocus(View view)

Gives focus to the default-focus view in the view hierarchy rooted at view.

static void saveAttributeDataForStyleable(View view, Context context, int[] styleable, AttributeSet attrs, TypedArray t, int defStyleAttr, int defStyleRes)

Stores debugging information about attributes.

static void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate)

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

static void setAccessibilityHeading(View view, boolean isHeading)

Set if view is a heading for a section of content for accessibility purposes.

static void setAccessibilityLiveRegion(View view, int mode)

Sets the live region mode for the specified view.

static void setAccessibilityPaneTitle(View view, CharSequence accessibilityPaneTitle)

Visually distinct portion of a window with window-like semantics are considered panes for accessibility purposes.

static void setActivated(View view, boolean activated)

This method is deprecated. Use View.setActivated(boolean) directly.

static void setAlpha(View view, float value)

This method is deprecated. Use View.setAlpha(float) directly.

static void setAutofillHints(View v, String... autofillHints)

Sets the hints that help an AutofillService determine how to autofill the view with the user's data.

static void setBackground(View view, Drawable background)

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

static void setBackgroundTintList(View view, ColorStateList tintList)

Applies a tint to the background drawable.

static void setBackgroundTintMode(View view, PorterDuff.Mode mode)

Specifies the blending mode used to apply the tint specified by setBackgroundTintList(android.view.View, android.content.res.ColorStateList) to the background drawable.

static void setChildrenDrawingOrderEnabled(ViewGroup viewGroup, boolean enabled)

This method is deprecated. Use ViewGroup.setChildrenDrawingOrderEnabled(boolean) directly.

static void setClipBounds(View view, Rect clipBounds)

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

static void setElevation(View view, float elevation)

Sets the base elevation of this view, in pixels.

static void setFitsSystemWindows(View view, boolean fitSystemWindows)

This method is deprecated. Use View.setFitsSystemWindows(boolean) directly.

static void setFocusedByDefault(View view, boolean isFocusedByDefault)

Sets whether view should receive focus when the focus is restored for the view hierarchy containing it.

static void setHasTransientState(View view, boolean hasTransientState)

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

static void setImportantForAccessibility(View view, 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.

static void setImportantForAutofill(View v, int mode)

Sets the mode for determining whether this view is considered important for autofill.

static void setKeyboardNavigationCluster(View view, boolean isCluster)

Set whether view is a root of a keyboard navigation cluster.

static void setLabelFor(View view, int labeledId)

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

static void setLayerPaint(View view, Paint paint)

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

static void setLayerType(View view, int layerType, Paint paint)

This method is deprecated. Use View.setLayerType(int, Paint) directly.

static void setLayoutDirection(View view, int layoutDirection)

Set the layout direction for this view.

static void setNestedScrollingEnabled(View view, boolean enabled)

Enable or disable nested scrolling for this view.

static void setNextClusterForwardId(View view, int nextClusterForwardId)

Sets the ID of the next keyboard navigation cluster root view.

static void setOnApplyWindowInsetsListener(View v, OnApplyWindowInsetsListener listener)

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

static void setOnReceiveContentListener(View view, String[] mimeTypes, OnReceiveContentListener listener)

Sets the listener to be used to handle insertion of content into the given view.

static void setOverScrollMode(View v, int overScrollMode)

This method is deprecated. Call View.setOverScrollMode(int) directly. This method will be removed in a future release.

static void setPaddingRelative(View view, int start, int top, int end, int bottom)

Sets the relative padding.

static void setPivotX(View view, float value)

This method is deprecated. Use View.setPivotX(float) directly.

static void setPivotY(View view, float value)

This method is deprecated. Use View.setPivotX(float) directly.

static void setPointerIcon(View view, PointerIconCompat pointerIcon)

Set the pointer icon for the current view.

static void setRotation(View view, float value)

This method is deprecated. Use View.setRotation(float) directly.

static void setRotationX(View view, float value)

This method is deprecated. Use View.setRotationX(float) directly.

static void setRotationY(View view, float value)

This method is deprecated. Use View.setRotationY(float) directly.

static void setSaveFromParentEnabled(View v, boolean enabled)

This method is deprecated. Use View.setSaveFromParentEnabled(boolean) directly.

static void setScaleX(View view, float value)

This method is deprecated. Use View.setScaleX(float) directly.

static void setScaleY(View view, float value)

This method is deprecated. Use View.setScaleY(float) directly.

static void setScreenReaderFocusable(View view, boolean screenReaderFocusable)

Sets whether this View should be a focusable element for screen readers and include non-focusable Views from its subtree when providing feedback.

static void setScrollIndicators(View view, int indicators, int mask)

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

static void setScrollIndicators(View view, int indicators)

Sets the state of all scroll indicators.

static void setStateDescription(View view, CharSequence stateDescription)

Sets the state description of this node.

static void setSystemGestureExclusionRects(View view, List<Rect> rects)

Sets a list of areas within this view's post-layout coordinate space where the system should not intercept touch or other pointing device gestures.

static void setTooltipText(View view, CharSequence tooltipText)

Sets the tooltip for the view.

static void setTransitionName(View view, String transitionName)

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

static void setTranslationX(View view, float value)

This method is deprecated. Use View.setTranslationX(float) directly.

static void setTranslationY(View view, float value)

This method is deprecated. Use View.setTranslationY(float) directly.

static void setTranslationZ(View view, float translationZ)

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

static void setWindowInsetsAnimationCallback(View view, WindowInsetsAnimationCompat.Callback callback)

Sets a WindowInsetsAnimationCompat.Callback to be notified about animations of windows that cause insets.

static void setX(View view, float value)

This method is deprecated. Use View.setX(float) directly.

static void setY(View view, float value)

This method is deprecated. Use View.setY(float) directly.

static void setZ(View view, float z)

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

static boolean startDragAndDrop(View v, ClipData data, View.DragShadowBuilder shadowBuilder, Object localState, int flags)

Start the drag and drop operation.

static boolean startNestedScroll(View view, int axes, int type)

Begin a nestable scroll operation along the given axes.

static boolean startNestedScroll(View view, int axes)

Begin a nestable scroll operation along the given axes.

static void stopNestedScroll(View view, int type)

Stop a nested scroll in progress.

static void stopNestedScroll(View view)

Stop a nested scroll in progress.

static void updateDragShadow(View v, View.DragShadowBuilder shadowBuilder)

Update the drag shadow while drag and drop is in progress.

Inherited methods

Constants

ACCESSIBILITY_LIVE_REGION_ASSERTIVE

public static final 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(View, int).

Constant Value: 2 (0x00000002)

ACCESSIBILITY_LIVE_REGION_NONE

public static final 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(View, int).

Constant Value: 0 (0x00000000)

ACCESSIBILITY_LIVE_REGION_POLITE

public static final int ACCESSIBILITY_LIVE_REGION_POLITE

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

Use with setAccessibilityLiveRegion(View, int).

Constant Value: 1 (0x00000001)

IMPORTANT_FOR_ACCESSIBILITY_AUTO

public static final int IMPORTANT_FOR_ACCESSIBILITY_AUTO

Automatically determine whether a view is important for accessibility.

Constant Value: 0 (0x00000000)

IMPORTANT_FOR_ACCESSIBILITY_NO

public static final int IMPORTANT_FOR_ACCESSIBILITY_NO

The view is not important for accessibility.

Constant Value: 2 (0x00000002)

IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS

public static final 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

public static final int IMPORTANT_FOR_ACCESSIBILITY_YES

The view is important for accessibility.

Constant Value: 1 (0x00000001)

LAYER_TYPE_HARDWARE

public static final int LAYER_TYPE_HARDWARE

This constant is deprecated.
Use View.LAYER_TYPE_HARDWARE directly.

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.

Constant Value: 2 (0x00000002)

LAYER_TYPE_NONE

public static final int LAYER_TYPE_NONE

This constant is deprecated.
Use View.LAYER_TYPE_NONE directly.

Indicates that the view does not have a layer.

Constant Value: 0 (0x00000000)

LAYER_TYPE_SOFTWARE

public static final int LAYER_TYPE_SOFTWARE

This constant is deprecated.
Use View.LAYER_TYPE_SOFTWARE directly.

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

Constant Value: 1 (0x00000001)

LAYOUT_DIRECTION_INHERIT

public static final int LAYOUT_DIRECTION_INHERIT

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

Constant Value: 2 (0x00000002)

LAYOUT_DIRECTION_LOCALE

public static final int LAYOUT_DIRECTION_LOCALE

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

Constant Value: 3 (0x00000003)

LAYOUT_DIRECTION_LTR

public static final int LAYOUT_DIRECTION_LTR

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

Constant Value: 0 (0x00000000)

LAYOUT_DIRECTION_RTL

public static final int LAYOUT_DIRECTION_RTL

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

Constant Value: 1 (0x00000001)

MEASURED_HEIGHT_STATE_SHIFT

public static final int MEASURED_HEIGHT_STATE_SHIFT

This constant is deprecated.
Use View.MEASURED_HEIGHT_STATE_SHIFT directly.

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(View) and the childState argument of resolveSizeAndState(int, int, int).

Constant Value: 16 (0x00000010)

MEASURED_SIZE_MASK

public static final int MEASURED_SIZE_MASK

This constant is deprecated.
Use View.MEASURED_SIZE_MASK directly.

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

Constant Value: 16777215 (0x00ffffff)

MEASURED_STATE_MASK

public static final int MEASURED_STATE_MASK

This constant is deprecated.
Use View.MEASURED_STATE_MASK directly.

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

Constant Value: -16777216 (0xff000000)

MEASURED_STATE_TOO_SMALL

public static final int MEASURED_STATE_TOO_SMALL

This constant is deprecated.
Use View.MEASURED_STATE_TOO_SMALL directly.

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

Constant Value: 16777216 (0x01000000)

OVER_SCROLL_ALWAYS

public static final int OVER_SCROLL_ALWAYS

This constant is deprecated.
Use View.OVER_SCROLL_ALWAYS directly. This constant will be removed in a future release.

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

Constant Value: 0 (0x00000000)

OVER_SCROLL_IF_CONTENT_SCROLLS

public static final int OVER_SCROLL_IF_CONTENT_SCROLLS

This constant is deprecated.
Use View.OVER_SCROLL_IF_CONTENT_SCROLLS directly. This constant will be removed in a future release.

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.

Constant Value: 1 (0x00000001)

OVER_SCROLL_NEVER

public static final int OVER_SCROLL_NEVER

This constant is deprecated.
Use View.OVER_SCROLL_NEVER directly. This constant will be removed in a future release.

Never allow a user to over-scroll this view.

Constant Value: 2 (0x00000002)

SCROLL_AXIS_HORIZONTAL

public static final int SCROLL_AXIS_HORIZONTAL

Indicates scrolling along the horizontal axis.

Constant Value: 1 (0x00000001)

SCROLL_AXIS_NONE

public static final int SCROLL_AXIS_NONE

Indicates no axis of view scrolling.

Constant Value: 0 (0x00000000)

SCROLL_AXIS_VERTICAL

public static final int SCROLL_AXIS_VERTICAL

Indicates scrolling along the vertical axis.

Constant Value: 2 (0x00000002)

SCROLL_INDICATOR_BOTTOM

public static final int SCROLL_INDICATOR_BOTTOM

Scroll indicator direction for the bottom edge of the view.

Constant Value: 2 (0x00000002)

SCROLL_INDICATOR_END

public static final int SCROLL_INDICATOR_END

Scroll indicator direction for the ending edge of the view.

Constant Value: 32 (0x00000020)

SCROLL_INDICATOR_LEFT

public static final int SCROLL_INDICATOR_LEFT

Scroll indicator direction for the left edge of the view.

Constant Value: 4 (0x00000004)

SCROLL_INDICATOR_RIGHT

public static final int SCROLL_INDICATOR_RIGHT

Scroll indicator direction for the right edge of the view.

Constant Value: 8 (0x00000008)

SCROLL_INDICATOR_START

public static final int SCROLL_INDICATOR_START

Scroll indicator direction for the starting edge of the view.

Constant Value: 16 (0x00000010)

SCROLL_INDICATOR_TOP

public static final int SCROLL_INDICATOR_TOP

Scroll indicator direction for the top edge of the view.

Constant Value: 1 (0x00000001)

TYPE_NON_TOUCH

public static final int TYPE_NON_TOUCH

Indicates that the input type for the gesture is caused by something which is not a user touching a screen. This is usually from a fling which is settling.

Constant Value: 1 (0x00000001)

TYPE_TOUCH

public static final int TYPE_TOUCH

Indicates that the input type for the gesture is from a user touching the screen.

Constant Value: 0 (0x00000000)

Protected constructors

ViewCompat

protected ViewCompat ()

This constructor is deprecated.
This is a utility class and it shouldn't be instantiated.

Public methods

addAccessibilityAction

public static int addAccessibilityAction (View view, 
                CharSequence label, 
                AccessibilityViewCommand command)

Adds an accessibility action that can be performed on a node associated with a view. A view can only have 32 actions created with this API.

Parameters
view View: The view.

label CharSequence: The use facing description of the action.

command AccessibilityViewCommand: The command performed when the service requests the action.

Returns
int The id associated with the action, or View.NO_ID if the action could not be created. This id can be used to remove the action.

Compatibility:

  • API < 21: No-op

addKeyboardNavigationClusters

public static void addKeyboardNavigationClusters (View view, 
                Collection<View> views, 
                int direction)

Adds any keyboard navigation cluster roots that are descendants of view ( including view if it is a cluster root itself) to views. Does nothing on API < 26.

Parameters
view View

views Collection: collection of keyboard navigation cluster roots found so far.

direction int: direction to look.

addOnUnhandledKeyEventListener

public static void addOnUnhandledKeyEventListener (View v, 
                ViewCompat.OnUnhandledKeyEventListenerCompat listener)

Adds a listener which will receive unhandled KeyEvents. This must be called on the UI thread.

Parameters
v View

listener ViewCompat.OnUnhandledKeyEventListenerCompat: a receiver of unhandled KeyEvents.

animate

public static ViewPropertyAnimatorCompat animate (View view)

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

Parameters
view View

Returns
ViewPropertyAnimatorCompat ViewPropertyAnimator The ViewPropertyAnimator associated with this View.

canScrollHorizontally

public static boolean canScrollHorizontally (View view, 
                int direction)

This method is deprecated.
Use View.canScrollHorizontally(int) directly.

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

Parameters
view View: The View against which to invoke the method.

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

public static boolean canScrollVertically (View view, 
                int direction)

This method is deprecated.
Use View.canScrollVertically(int) directly.

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

Parameters
view View: The View against which to invoke the method.

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

public static void cancelDragAndDrop (View v)

Cancel the drag and drop operation.

Parameters
v View

combineMeasuredStates

public static int combineMeasuredStates (int curState, 
                int newState)

This method is deprecated.
Use View.combineMeasuredStates(int, int) directly.

Merge two states as returned by getMeasuredState(View).

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.

computeSystemWindowInsets

public static WindowInsetsCompat computeSystemWindowInsets (View view, 
                WindowInsetsCompat insets, 
                Rect outLocalInsets)

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

Parameters
view View

insets WindowInsetsCompat: Insets currently being processed by this View, likely received as a parameter to View.onApplyWindowInsets(WindowInsets).

outLocalInsets Rect: A Rect that will receive the insets that should be consumed by this view

Returns
WindowInsetsCompat Insets that should be passed along to views under this one

dispatchApplyWindowInsets

public static WindowInsetsCompat dispatchApplyWindowInsets (View view, 
                WindowInsetsCompat 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.

Parameters
view View

insets WindowInsetsCompat: Insets to apply

Returns
WindowInsetsCompat The provided insets minus the insets that were consumed

dispatchFinishTemporaryDetach

public static void dispatchFinishTemporaryDetach (View view)

Notify a view that its temporary detach has ended; the view is now reattached.

Parameters
view View

dispatchNestedFling

public static boolean dispatchNestedFling (View view, 
                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
view View

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

public static boolean dispatchNestedPreFling (View view, 
                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
view View

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

dispatchNestedPreScroll

public static boolean dispatchNestedPreScroll (View view, 
                int dx, 
                int dy, 
                int[] consumed, 
                int[] offsetInWindow, 
                int type)

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
view View

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.

type int: the type of input which cause this scroll event

Returns
boolean true if the parent consumed some or all of the scroll delta

dispatchNestedPreScroll

public static boolean dispatchNestedPreScroll (View view, 
                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.

This version of the method just calls dispatchNestedPreScroll(View, int, int, int[], int[], int) using the touch input type.

Parameters
view View

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

dispatchNestedScroll

public static boolean dispatchNestedScroll (View view, 
                int dxConsumed, 
                int dyConsumed, 
                int dxUnconsumed, 
                int dyUnconsumed, 
                int[] offsetInWindow, 
                int type)

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
view View

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.

type int: the type of input which cause this scroll event

Returns
boolean true if the event was dispatched, and therefore the scroll distance was consumed

dispatchNestedScroll

public static boolean dispatchNestedScroll (View view, 
                int dxConsumed, 
                int dyConsumed, 
                int dxUnconsumed, 
                int dyUnconsumed, 
                int[] offsetInWindow)

Dispatch one step of a nested scroll in progress.

This version of the method just calls dispatchNestedScroll(View, int, int, int, int, int[], int) using the touch input type.

Parameters
view View

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.

dispatchNestedScroll

public static void dispatchNestedScroll (View view, 
                int dxConsumed, 
                int dyConsumed, 
                int dxUnconsumed, 
                int dyUnconsumed, 
                int[] offsetInWindow, 
                int type, 
                int[] consumed)

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.

A non-null consumed int array of length 2 may be passed in to enable nested scrolling parents to report how much of the scroll distance was consumed. The original caller (where the input event was received to start the scroll) should initialize the values to be 0, in order to tell how much was actually consumed up the hierarchy of scrolling parents.

Parameters
view View

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.

type int: the type of input which cause this scroll event

consumed int: Output, If not null, consumed[0] will contain the consumed component of dx and consumed[1] the consumed dy.

dispatchStartTemporaryDetach

public static void dispatchStartTemporaryDetach (View view)

Notify a view that it is being temporarily detached.

Parameters
view View

enableAccessibleClickableSpanSupport

public static void enableAccessibleClickableSpanSupport (View view)

Allow accessibility services to find and activate clickable spans in the application.

Parameters
view View: The view

Compatibility:

  • API < 19: No-op

generateViewId

public static int generateViewId ()

Generate a value suitable for use in View.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

getAccessibilityDelegate

public static AccessibilityDelegateCompat getAccessibilityDelegate (View view)

Get the current accessibility delegate.

Parameters
view View: The view whose delegate is of interest

Returns
AccessibilityDelegateCompat A compat wrapper for the current delegate. If no delegate is attached, you may still get an object that is being used to provide backward compatibility. Returns null if there is no delegate attached.

getAccessibilityLiveRegion

public static int getAccessibilityLiveRegion (View view)

Gets the live region mode for the specified View.

Parameters
view View: The view from which to obtain the live region mode

Returns
int The live region mode for the view.

getAccessibilityNodeProvider

public static AccessibilityNodeProviderCompat getAccessibilityNodeProvider (View view)

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 AccessibilityNodeInfoCompats 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 AccessibilityDelegateCompat has been specified via calling setAccessibilityDelegate(View, AccessibilityDelegateCompat) its AccessibilityDelegateCompat.getAccessibilityNodeProvider(View) is responsible for handling this call.

Parameters
view View: The view whose property to get.

Returns
AccessibilityNodeProviderCompat The provider.

getAccessibilityPaneTitle

public static CharSequence getAccessibilityPaneTitle (View view)

Get the title of the pane for purposes of accessibility.

Parameters
view View: The view queried for it's pane title.

Compatibility:

  • API < 19: Always returns null

Returns
CharSequence The current pane title. .

getAlpha

public static float getAlpha (View view)

This method is deprecated.
Use View.getAlpha() directly.

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.

Parameters
view View

Returns
float The opacity of the view.

getBackgroundTintList

public static ColorStateList getBackgroundTintList (View view)

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

Only returns meaningful info when running on API v21 or newer, or if view implements the TintableBackgroundView interface.

Parameters
view View

Returns
ColorStateList

getBackgroundTintMode

public static PorterDuff.Mode getBackgroundTintMode (View view)

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

Only returns meaningful info when running on API v21 or newer, or if view implements the TintableBackgroundView interface.

Parameters
view View

Returns
PorterDuff.Mode

getClipBounds

public static Rect getClipBounds (View view)

Returns a copy of the current setClipBounds(View, Rect).

Prior to API 18 this will return null.

Parameters
view View

Returns
Rect A copy of the current clip bounds if clip bounds are set, otherwise null.

getDisplay

public static Display getDisplay (View view)

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

Compatibility:

  • API < 17: Returns the default display when the view is attached. Otherwise, null.

Parameters
view View

Returns
Display The logical display, or null if the view is not currently attached to a window.

getElevation

public static float getElevation (View view)

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

Parameters
view View

Returns
float The base depth position of the view, in pixels.

getFitsSystemWindows

public static boolean getFitsSystemWindows (View v)

Returns true if this view should adapt to fit system window insets. This method will always return false before API 16 (Jellybean).

Parameters
v View

Returns
boolean

getImportantForAccessibility

public static int getImportantForAccessibility (View view)

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.

Parameters
view View: The view whose property to get.

Returns
int The mode for determining whether a View is important for accessibility.

getImportantForAutofill

public static int getImportantForAutofill (View v)

Gets the mode for determining whether this view is important for autofill.

See setImportantForAutofill(View, int) and isImportantForAutofill(View) for more info about this mode.

This method is only supported on API >= 26. On API 25 and below, it will always return View.IMPORTANT_FOR_AUTOFILL_AUTO.

Parameters
v View

Returns
int View.IMPORTANT_FOR_AUTOFILL_AUTO by default, or value passed to setImportantForAutofill(View, int). R.attr.importantForAutofill

getLabelFor

public static int getLabelFor (View view)

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

Parameters
view View: The view on which to invoke the corresponding method.

Returns
int The labeled view id.

getLayerType

public static int getLayerType (View view)

This method is deprecated.
Use View.getLayerType() directly.

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 View.LAYER_TYPE_NONE. Refer to the documentation of setLayerType(android.view.View, int, android.graphics.Paint) for more information on the different types of layers.

Parameters
view View: The view to fetch the layer type from

Returns
int View.LAYER_TYPE_NONE, View.LAYER_TYPE_SOFTWARE or View.LAYER_TYPE_HARDWARE

getLayoutDirection

public static int getLayoutDirection (View view)

Returns the resolved layout direction for this view.

Parameters
view View: View to get layout direction for

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 Jellybean MR1 (API 17)

getMatrix

public static Matrix getMatrix (View view)

This method is deprecated.
Use View.getMatrix() directly.

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

Parameters
view View: The view whose Matrix will be returned

Returns
Matrix The current transform matrix for the view

getMeasuredHeightAndState

public static int getMeasuredHeightAndState (View view)

This method is deprecated.
Use View.getMeasuredHeightAndState() directly.

Return the full height measurement information for this view as computed by the most recent call to View.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 View.getHeight() to see how wide a view is after layout.

Parameters
view View

Returns
int The measured width of this view as a bit mask.

getMeasuredState

public static int getMeasuredState (View view)

This method is deprecated.
Use View.getMeasuredState() directly.

Return only the state bits of getMeasuredWidthAndState(View) and getMeasuredHeightAndState(View), 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.

Parameters
view View

Returns
int

getMeasuredWidthAndState

public static int getMeasuredWidthAndState (View view)

This method is deprecated.
Use View.getMeasuredWidth() directly.

Return the full width measurement information for this view as computed by the most recent call to View.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 View.getWidth() to see how wide a view is after layout.

Parameters
view View

Returns
int The measured width of this view as a bit mask.

getMinimumHeight

public static int getMinimumHeight (View view)

Returns the minimum height of the view.

Prior to API 16, this method may return 0 on some platforms.

Parameters
view View

Returns
int the minimum height the view will try to be.

getMinimumWidth

public static int getMinimumWidth (View view)

Returns the minimum width of the view.

Prior to API 16, this method may return 0 on some platforms.

Parameters
view View

Returns
int the minimum width the view will try to be.

getNextClusterForwardId

public static int getNextClusterForwardId (View view)

Gets the ID of the next keyboard navigation cluster root.

Parameters
view View

Returns
int the next keyboard navigation cluster ID, or View.NO_ID if the framework should decide automatically or API < 26.

getOnReceiveContentMimeTypes

public static String[] getOnReceiveContentMimeTypes (View view)

Returns the MIME types accepted by the listener configured on the given view via setOnReceiveContentListener(View, String[], OnReceiveContentListener). By default returns null.

Different features (e.g. pasting from the clipboard, inserting stickers from the soft keyboard, etc) may optionally use this metadata to conditionally alter their behavior. For example, a soft keyboard may choose to hide its UI for inserting GIFs for a particular input field if the MIME types returned here for that field don't include "image/gif" or "image/*".

Note: Comparisons of MIME types should be performed using utilities such as ClipDescription.compareMimeTypes(String, String) rather than simple string equality, in order to correctly handle patterns such as "text/*", "image/*", etc. Note that MIME type matching in the Android framework is case-sensitive, unlike formal RFC MIME types. As a result, you should always write your MIME types with lowercase letters, or use Intent.normalizeMimeType(String) to ensure that it is converted to lowercase.

Parameters
view View: The target view.

Returns
String[] The MIME types accepted by the OnReceiveContentListener for the given view (may include patterns such as "image/*").

getOverScrollMode

public static int getOverScrollMode (View v)

This method is deprecated.
Call View.getOverScrollMode() directly. This method will be removed in a future release.

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.

Parameters
v View: The View against which to invoke the method.

Returns
int This view's over-scroll mode.

getPaddingEnd

public static int getPaddingEnd (View view)

Returns the end padding of the specified 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.

Parameters
view View: The view to get padding for

Returns
int the end padding in pixels

getPaddingStart

public static int getPaddingStart (View view)

Returns the start padding of the specified 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.

Parameters
view View: The view to get padding for

Returns
int the start padding in pixels

getParentForAccessibility

public static ViewParent getParentForAccessibility (View view)

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.

Parameters
view View: View to retrieve parent for

Returns
ViewParent The parent for use in accessibility inspection

getPivotX

public static float getPivotX (View view)

This method is deprecated.
Use View.getPivotX() directly.

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

Parameters
view View

Returns
float

getPivotY

public static float getPivotY (View view)

This method is deprecated.
Use View.getPivotY() directly.

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

Parameters
view View

Returns
float The y location of the pivot point.

getRootWindowInsets

public static WindowInsetsCompat getRootWindowInsets (View view)

Provide original WindowInsetsCompat that are dispatched to the view hierarchy. The insets are only available if the view is attached.

On devices running API 22 and below, this method always returns null.

Parameters
view View

Returns
WindowInsetsCompat WindowInsetsCompat from the top of the view hierarchy or null if View is detached

getRotation

public static float getRotation (View view)

This method is deprecated.
Use View.getRotation() directly.

Parameters
view View

Returns
float

getRotationX

public static float getRotationX (View view)

This method is deprecated.
Use View.getRotationX() directly.

Parameters
view View

Returns
float

getRotationY

public static float getRotationY (View view)

This method is deprecated.
Use View.getRotationY() directly.

Parameters
view View

Returns
float

getScaleX

public static float getScaleX (View view)

This method is deprecated.
Use View.getScaleX() directly.

Parameters
view View

Returns
float

getScaleY

public static float getScaleY (View view)

This method is deprecated.
Use View.getScaleY() directly.

Parameters
view View

Returns
float

getScrollIndicators

public static int getScrollIndicators (View view)

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 ViewCompat.SCROLL_INDICATOR_TOP | ViewCompat.SCROLL_INDICATOR_LEFT.

To check whether the bottom scroll indicator is enabled, use the value of (ViewCompat.getScrollIndicators(view) & ViewCompat.SCROLL_INDICATOR_BOTTOM) != 0.

Parameters
view View

Returns
int a bitmask representing the enabled scroll indicators

getStateDescription

public static final CharSequence getStateDescription (View view)

Returns the View's state description.

Note: Do not override this method, as it will have no effect on the state description presented to accessibility services. You must call setStateDescription(View, CharSequence) to modify the state description.

Parameters
view View

Returns
CharSequence the state description

getSystemGestureExclusionRects

public static List<Rect> getSystemGestureExclusionRects (View view)

Retrieve the list of areas within this view's post-layout coordinate space where the system should not intercept touch or other pointing device gestures.

On devices running API 28 and below, this method always returns an empty list.

Parameters
view View

Returns
List<Rect>

getTransitionName

public static String getTransitionName (View view)

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.

Parameters
view View: The View against which to invoke the method.

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

public static float getTranslationX (View view)

This method is deprecated.
Use View.getTranslationX() directly.

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.

Parameters
view View

Returns
float The horizontal position of this view relative to its left position, in pixels.

getTranslationY

public static float getTranslationY (View view)

This method is deprecated.
Use View.getTranslationY() directly.

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.

Parameters
view View

Returns
float The vertical position of this view relative to its top position, in pixels.

getTranslationZ

public static float getTranslationZ (View view)

The depth location of this view relative to its elevation.

Parameters
view View

Returns
float The depth of this view relative to its elevation.

getWindowInsetsController

public static WindowInsetsControllerCompat getWindowInsetsController (View view)

Retrieves a WindowInsetsControllerCompat of the window this view is attached to.

Parameters
view View

Returns
WindowInsetsControllerCompat A WindowInsetsControllerCompat or null if the view is neither attached to a window nor a view tree with a decor.

getWindowSystemUiVisibility

public static int getWindowSystemUiVisibility (View view)

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

Parameters
view View

Returns
int

getX

public static float getX (View view)

This method is deprecated.
Use View.getX() directly.

Parameters
view View

Returns
float

getY

public static float getY (View view)

This method is deprecated.
Use View.getY() directly.

Parameters
view View

Returns
float

getZ

public static float getZ (View view)

The visual z position of this view, in pixels. This is equivalent to the translationZ property plus the current elevation property.

Parameters
view View

Returns
float The visual z position of this view, in pixels.

hasAccessibilityDelegate

public static boolean hasAccessibilityDelegate (View view)

Checks whether provided View has an accessibility delegate attached to it.

Parameters
view View: The View instance to check

Returns
boolean True if the View has an accessibility delegate

hasExplicitFocusable

public static boolean hasExplicitFocusable (View view)

Returns true if this view is focusable or if it contains a reachable View for which View.hasExplicitFocusable() returns true. A "reachable hasExplicitFocusable()" is a view whose parents do not block descendants focus. Only View.VISIBLE views for which View.getFocusable() would return View.FOCUSABLE are considered focusable.

This method preserves the pre-Build.VERSION_CODES.O behavior of View.hasFocusable() in that only views explicitly set focusable will cause this method to return true. A view set to View.FOCUSABLE_AUTO that resolves to focusable will not.

Parameters
view View

Returns
boolean true if the view is focusable or if the view contains a focusable view, false otherwise

hasNestedScrollingParent

public static boolean hasNestedScrollingParent (View view, 
                int type)

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.

Parameters
view View

type int: the type of input which cause this scroll event

Returns
boolean whether this view has a nested scrolling parent

hasNestedScrollingParent

public static boolean hasNestedScrollingParent (View view)

Returns true if this view has a nested scrolling parent.

This version of the method just calls hasNestedScrollingParent(View, int) using the touch input type.

Parameters
view View

Returns
boolean whether this view has a nested scrolling parent

hasOnClickListeners

public static boolean hasOnClickListeners (View view)

Returns whether the provided view has an attached View.OnClickListener.

Parameters
view View

Returns
boolean true if there is a listener, false if there is none.

hasOverlappingRendering

public static boolean hasOverlappingRendering (View view)

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.

Parameters
view View

Returns
boolean true if the content in this view might overlap, false otherwise.

hasTransientState

public static boolean hasTransientState (View view)

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.

Parameters
view View: View to check for transient state

Returns
boolean true if the view has transient state

isAccessibilityHeading

public static boolean isAccessibilityHeading (View view)

Gets whether this view is a heading for accessibility purposes.

Parameters
view View: The view checked if it is a heading.

Compatibility:

  • API < 19: Always returns false

Returns
boolean true if the view is a heading, false otherwise.

isAttachedToWindow

public static boolean isAttachedToWindow (View view)

Returns true if the provided view is currently attached to a window.

Parameters
view View

Returns
boolean

isFocusedByDefault

public static boolean isFocusedByDefault (View view)

Returns whether view should receive focus when the focus is restored for the view hierarchy containing it. Returns false on API < 26.

Focus gets restored for a view hierarchy when the root of the hierarchy gets added to a window or serves as a target of cluster navigation.

Parameters
view View

Returns
boolean true if view is the default-focus view, false otherwise.

isImportantForAccessibility

public static boolean isImportantForAccessibility (View view)

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(View) 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:

Note: Prior to API 21, this method will always return true.

Parameters
view View

Returns
boolean Whether the view is exposed for accessibility.

isImportantForAutofill

public static boolean isImportantForAutofill (View v)

Hints the Android System whether the AssistStructure.ViewNode associated with this view is considered important for autofill purposes.

Generally speaking, a view is important for autofill if:

  1. The view can be autofilled by an AutofillService.
  2. The view contents can help an AutofillService determine how other views can be autofilled.

      For example, view containers should typically return false for performance reasons (since the important info is provided by their children), but if its properties have relevant information (for example, a resource id called credentials, it should return true. On the other hand, views representing labels or editable fields should typically return true, but in some cases they could return false (for example, if they're part of a "Captcha" mechanism).

      The value returned by this method depends on the value returned by getImportantForAutofill(View):

      1. if it returns