ViewCompat
public class ViewCompat
Helper for accessing features in View.
Summary
Nested types |
|---|
public interface ViewCompat.OnUnhandledKeyEventListenerCompatInterface definition for a callback to be invoked when a hardware key event hasn't been handled by the view hierarchy. |
Constants |
|
|---|---|
static final int |
Live region mode specifying that accessibility services should interrupt ongoing speech to immediately announce changes to this view. |
static final int |
Live region mode specifying that accessibility services should not automatically announce changes to this view. |
static final int |
Live region mode specifying that accessibility services should announce changes to this view. |
static final int |
This field is deprecated. Use |
static final int |
This field is deprecated. Use |
static final int |
This field is deprecated. Use |
static final int |
This field is deprecated. Use |
static final int |
Automatically determine whether a view is important for content capture. |
static final int |
The view is not important for content capture, but its children (if any) will be traversed. |
static final int |
The view is not important for content capture, and its children (if any) will not be traversed. |
static final int |
The view is important for content capture, and its children (if any) will be traversed. |
static final int |
The view is important for content capture, but its children (if any) will not be traversed. |
static final int |
This field is deprecated. Use |
static final int |
LAYER_TYPE_NONE = 0This field is deprecated. Use |
static final int |
This field is deprecated. Use |
static final int |
This field is deprecated. Use |
static final int |
This field is deprecated. Use |
static final int |
This field is deprecated. Use |
static final int |
This field is deprecated. Use |
static final int |
This field is deprecated. Use |
static final int |
MEASURED_SIZE_MASK = 16777215This field is deprecated. Use |
static final int |
MEASURED_STATE_MASK = -16777216This field is deprecated. Use |
static final int |
MEASURED_STATE_TOO_SMALL = 16777216This field is deprecated. Use |
static final int |
This field is deprecated. Use |
static final int |
This field is deprecated. Use |
static final int |
This field is deprecated. Use |
static final int |
Indicates scrolling along the horizontal axis. |
static final int |
SCROLL_AXIS_NONE = 0Indicates no axis of view scrolling. |
static final int |
Indicates scrolling along the vertical axis. |
static final int |
Scroll indicator direction for the bottom edge of the view. |
static final int |
SCROLL_INDICATOR_END = 32Scroll indicator direction for the ending edge of the view. |
static final int |
Scroll indicator direction for the left edge of the view. |
static final int |
Scroll indicator direction for the right edge of the view. |
static final int |
Scroll indicator direction for the starting edge of the view. |
static final int |
Scroll indicator direction for the top edge of the view. |
static final int |
TYPE_NON_TOUCH = 1Indicates that the input type for the gesture is caused by something which is not a user touching a screen. |
static final int |
TYPE_TOUCH = 0Indicates that the input type for the gesture is from a user touching the screen. |
Protected constructors |
|---|
|
This method is deprecated. This is a utility class and it shouldn't be instantiated. |
Public methods |
|
|---|---|
static int |
addAccessibilityAction(Adds an accessibility action that can be performed on a node associated with a view. |
static void |
addKeyboardNavigationClusters(Adds any keyboard navigation cluster roots that are descendants of |
static void |
addOnUnhandledKeyEventListener(Adds a listener which will receive unhandled |
static void |
addOverlayView(@NonNull ViewGroup overlayHost, @NonNull View overlay)Convenience method to add |
static @NonNull ViewPropertyAnimatorCompat |
This method is deprecated. Call |
static boolean |
@ReplaceWith(expression = "view.canScrollHorizontally(direction)")This method is deprecated. Use |
static boolean |
@ReplaceWith(expression = "view.canScrollVertically(direction)")This method is deprecated. Use |
static void |
Cancel the drag and drop operation. |
static int |
This method is deprecated. Use |
static @NonNull WindowInsetsCompat |
computeSystemWindowInsets(Compute insets that should be consumed by this view and the ones that should propagate to those under it. |
static @NonNull WindowInsetsCompat |
dispatchApplyWindowInsets(Request to apply the given window insets to this view or another view in its subtree. |
static void |
Notify a view that its temporary detach has ended; the view is now reattached. |
static boolean |
dispatchNestedFling(Dispatch a fling to a nested scrolling parent. |
static boolean |
dispatchNestedPreFling(Dispatch a fling to a nested scrolling parent before it is processed by this view. |
static boolean |
dispatchNestedPreScroll(Dispatch one step of a nested scroll in progress before this view consumes any portion of it. |
static boolean |
dispatchNestedPreScroll(Dispatch one step of a nested scroll in progress before this view consumes any portion of it. |
static boolean |
dispatchNestedScroll(Dispatch one step of a nested scroll in progress. |
static boolean |
dispatchNestedScroll(Dispatch one step of a nested scroll in progress. |
static void |
dispatchNestedScroll(Dispatch one step of a nested scroll in progress. |
static void |
Notify a view that it is being temporarily detached. |
static void |
Allow accessibility services to find and activate clickable spans in the application. |
static int |
This method is deprecated. Call |
static @Nullable AccessibilityDelegateCompat |
getAccessibilityDelegate(@NonNull View view)Get the current accessibility delegate. |
static int |
@ReplaceWith(expression = "view.getAccessibilityLiveRegion()")This method is deprecated. Call |
static @Nullable AccessibilityNodeProviderCompat |
Gets the provider for managing a virtual view hierarchy rooted at this View and reported to |
static @Nullable CharSequence |
Get the title of the pane for purposes of accessibility. |
static float |
@ReplaceWith(expression = "view.getAlpha()")This method is deprecated. Use |
static @Nullable AutofillIdCompat |
getAutofillId(@NonNull View v)Gets the unique, logical identifier of this view in the activity, for autofill purposes. |
static @Nullable ColorStateList |
getBackgroundTintList(@NonNull View view)Return the tint applied to the background drawable, if specified. |
static @Nullable PorterDuff.Mode |
getBackgroundTintMode(@NonNull View view)Return the blending mode used to apply the tint to the background drawable, if specified. |
static @Nullable Rect |
@ReplaceWith(expression = "view.getClipBounds()")This method is deprecated. Call |
static @Nullable ContentCaptureSessionCompat |
Gets the session used to notify content capture events. |
static @Nullable Display |
@ReplaceWith(expression = "view.getDisplay()")This method is deprecated. Call |
static float |
getElevation(@NonNull View view)The base elevation of this view relative to its parent, in pixels. |
static boolean |
@ReplaceWith(expression = "view.getFitsSystemWindows()")This method is deprecated. Call |
static int |
@ReplaceWith(expression = "view.getImportantForAccessibility()")This method is deprecated. Call |
static int |
Gets the mode for determining whether this view is important for autofill. |
static int |
Gets the mode for determining whether this view is important for content capture. |
static int |
@ReplaceWith(expression = "view.getLabelFor()")This method is deprecated. Call |
static int |
@ReplaceWith(expression = "view.getLayerType()")This method is deprecated. Use |
static int |
@ReplaceWith(expression = "view.getLayoutDirection()")This method is deprecated. Call |
static @Nullable Matrix |
@ReplaceWith(expression = "view.getMatrix()")This method is deprecated. Use |
static int |
@ReplaceWith(expression = "view.getMeasuredHeightAndState()")This method is deprecated. Use |
static int |
@ReplaceWith(expression = "view.getMeasuredState()")This method is deprecated. Use |
static int |
@ReplaceWith(expression = "view.getMeasuredWidthAndState()")This method is deprecated. Use |
static int |
@ReplaceWith(expression = "view.getMinimumHeight()")This method is deprecated. Call |
static int |
@ReplaceWith(expression = "view.getMinimumWidth()")This method is deprecated. Call |
static int |
getNextClusterForwardId(@NonNull View view)Gets the ID of the next keyboard navigation cluster root. |
static @Nullable String[] |
Returns the MIME types accepted by the listener configured on the given view via |
static int |
@ReplaceWith(expression = "view.getOverScrollMode()")This method is deprecated. Call |
static @Px int |
@ReplaceWith(expression = "view.getPaddingEnd()")This method is deprecated. Call |
static @Px int |
@ReplaceWith(expression = "view.getPaddingStart()")This method is deprecated. Call |
static @Nullable ViewParent |
@ReplaceWith(expression = "view.getParentForAccessibility()")This method is deprecated. Call |
static float |
@ReplaceWith(expression = "view.getPivotX()")This method is deprecated. Use |
static float |
@ReplaceWith(expression = "view.getPivotY()")This method is deprecated. Use |
static @Nullable WindowInsetsCompat |
getRootWindowInsets(@NonNull View view)Provide original |
static float |
@ReplaceWith(expression = "view.getRotation()")This method is deprecated. Use |
static float |
@ReplaceWith(expression = "view.getRotationX()")This method is deprecated. Use |
static float |
@ReplaceWith(expression = "view.getRotationY()")This method is deprecated. Use |
static float |
@ReplaceWith(expression = "view.getScaleX()")This method is deprecated. Use |
static float |
@ReplaceWith(expression = "view.getScaleY()")This method is deprecated. Use |
static int |
getScrollIndicators(@NonNull View view)Returns a bitmask representing the enabled scroll indicators. |
static @Nullable CharSequence |
@UiThreadReturns the |
static @NonNull List<Rect> |
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 @Nullable String |
getTransitionName(@NonNull View view)Returns the name of the View to be used to identify Views in Transitions. |
static float |
@ReplaceWith(expression = "view.getTranslationX()")This method is deprecated. Use |
static float |
@ReplaceWith(expression = "view.getTranslationY()")This method is deprecated. Use |
static float |
getTranslationZ(@NonNull View view)The depth location of this view relative to its |
static @Nullable WindowInsetsControllerCompat |
This method is deprecated. Prefer |
static int |
@ReplaceWith(expression = "view.getWindowSystemUiVisibility()")This method is deprecated. SystemUiVisibility flags are deprecated. |
static float |
@ReplaceWith(expression = "view.getX()")This method is deprecated. Use |
static float |
@ReplaceWith(expression = "view.getY()")This method is deprecated. Use |
static float |
The visual z position of this view, in pixels. |
static boolean |
hasAccessibilityDelegate(@NonNull View view)Checks whether provided View has an accessibility delegate attached to it. |
static boolean |
hasExplicitFocusable(@NonNull View view)Returns true if this view is focusable or if it contains a reachable View for which |
static boolean |
hasNestedScrollingParent(@NonNull View view)Returns true if this view has a nested scrolling parent. |
static boolean |
hasNestedScrollingParent(@NonNull View view, int type)Returns true if this view has a nested scrolling parent. |
static boolean |
@ReplaceWith(expression = "view.hasOnClickListeners()")This method is deprecated. Call |
static boolean |
@ReplaceWith(expression = "view.hasOverlappingRendering()")This method is deprecated. Call |
static boolean |
@ReplaceWith(expression = "view.hasTransientState()")This method is deprecated. Call |
static boolean |
Gets whether this view is a heading for accessibility purposes. |
static boolean |
@ReplaceWith(expression = "view.isAttachedToWindow()")This method is deprecated. Call |
static boolean |
isFocusedByDefault(@NonNull View view)Returns whether |
static boolean |
Computes whether this view should be exposed for accessibility. |
static boolean |
Hints the Android System whether the |
static boolean |
Hints the Android System whether this view is considered important for content capture, based on the value explicitly set by setImportantForContentCapture and heuristics when it's |
static boolean |
@ReplaceWith(expression = "view.isInLayout()")This method is deprecated. Call |
static boolean |
Returns whether |
static boolean |
@ReplaceWith(expression = "view.isLaidOut()")This method is deprecated. Call |
static boolean |
@ReplaceWith(expression = "view.isLayoutDirectionResolved()")This method is deprecated. Call |
static boolean |
isNestedScrollingEnabled(@NonNull View view)Returns true if nested scrolling is enabled for this view. |
static boolean |
@ReplaceWith(expression = "view.isOpaque()")This method is deprecated. Use |
static boolean |
@ReplaceWith(expression = "view.isPaddingRelative()")This method is deprecated. Call |
static boolean |
Returns whether the view should be treated as a focusable unit by screen reader accessibility tools. |
static void |
@ReplaceWith(expression = "view.jumpDrawablesToCurrentState()")This method is deprecated. Use |
static @Nullable View |
keyboardNavigationClusterSearch(Find the nearest keyboard navigation cluster in the specified direction. |
static void |
offsetLeftAndRight(@NonNull View view, int offset)Offset this view's horizontal location by the specified amount of pixels. |
static void |
offsetTopAndBottom(@NonNull View view, int offset)Offset this view's vertical location by the specified number of pixels. |
static @NonNull WindowInsetsCompat |
onApplyWindowInsets(@NonNull View view, @NonNull WindowInsetsCompat insets)Called when the view should apply |
static void |
@ReplaceWith(expression = "v.onInitializeAccessibilityEvent(event)")This method is deprecated. Call |
static void |
@ReplaceWith(expression = "v.onInitializeAccessibilityNodeInfo(info.unwrap())")This method is deprecated. Call |
static void |
@ReplaceWith(expression = "v.onPopulateAccessibilityEvent(event)")This method is deprecated. Call |
static boolean |
@ReplaceWith(expression = "view.performAccessibilityAction(action, arguments)")This method is deprecated. Call |
static boolean |
performHapticFeedback(@NonNull View view, int feedbackConstant)Perform a haptic feedback to the user for the view. |
static boolean |
performHapticFeedback(@NonNull View view, int feedbackConstant, int flags)Perform a haptic feedback to the user for the view. |
static @Nullable ContentInfoCompat |
performReceiveContent(Receives the given content. |
static void |
@ReplaceWith(expression = "view.postInvalidateOnAnimation()")This method is deprecated. Call |
static void |
@ReplaceWith(expression = "view.postInvalidateOnAnimation(left, top, right, bottom)")This method is deprecated. Call |
static void |
@ReplaceWith(expression = "view.postOnAnimation(action)")This method is deprecated. Call |
static void |
@ReplaceWith(expression = "view.postOnAnimationDelayed(action, delayMillis)")This method is deprecated. Call |
static void |
removeAccessibilityAction(@NonNull View view, int actionId)Removes an accessibility action that can be performed on a node associated with a view. |
static void |
removeOnUnhandledKeyEventListener(Removes a listener which will receive unhandled |
static void |
replaceAccessibilityAction(Replaces an action. |
static void |
requestApplyInsets(@NonNull View view)Ask that a new dispatch of |
static @NonNull T |
<T extends View> requireViewById(@NonNull View view, @IdRes int id)Finds the first descendant view with the given ID, the view itself if the ID matches |
static int |
This method is deprecated. Use |
static boolean |
restoreDefaultFocus(@NonNull View view)Gives focus to the default-focus view in the view hierarchy rooted at |
static void |
saveAttributeDataForStyleable(Stores debugging information about attributes. |
static void |
setAccessibilityDelegate(Sets a delegate for implementing accessibility support via composition (as opposed to inheritance). |
static void |
@UiThreadSet if view is a heading for a section of content for accessibility purposes. |
static void |
@ReplaceWith(expression = "view.setAccessibilityLiveRegion(mode)")This method is deprecated. Call |
static void |
@UiThreadVisually distinct portion of a window with window-like semantics are considered panes for accessibility purposes. |
static void |
@ReplaceWith(expression = "view.setActivated(activated)")This method is deprecated. Use |
static void |
@ReplaceWith(expression = "view.setAlpha(value)")This method is deprecated. Use |
static void |
setAutofillHints(@NonNull View view, @Nullable String[] autofillHints)Sets the hints that help an |
static void |
setAutofillId(@NonNull View v, @Nullable AutofillIdCompat id)Sets the unique, logical identifier of this view in the activity, for autofill purposes. |
static void |
@ReplaceWith(expression = "view.setBackground(background)")This method is deprecated. Call |
static void |
setBackgroundTintList(Applies a tint to the background drawable. |
static void |
setBackgroundTintMode(@NonNull View view, @Nullable PorterDuff.Mode mode)Specifies the blending mode used to apply the tint specified by |
static void |
This method is deprecated. Use |
static void |
@ReplaceWith(expression = "view.setClipBounds(clipBounds)")This method is deprecated. Call |
static void |
setContentCaptureSession(Sets the (optional) |
static void |
setElevation(@NonNull View view, float elevation) |
static void |
@ReplaceWith(expression = "view.setFitsSystemWindows(fitSystemWindows)")This method is deprecated. Use |
static void |
setFocusedByDefault(@NonNull View view, boolean isFocusedByDefault)Sets whether |
static void |
@ReplaceWith(expression = "view.setHasTransientState(hasTransientState)")This method is deprecated. Call |
static void |
@ReplaceWith(expression = "view.setImportantForAccessibility(mode)")This method is deprecated. Call |
static void |
setImportantForAutofill(@NonNull View v, int mode)Sets the mode for determining whether this view is considered important for autofill. |
static void |
setImportantForContentCapture(@NonNull View v, int mode)Sets the mode for determining whether this view is considered important for content capture. |
static void |
setKeyboardNavigationCluster(@NonNull View view, boolean isCluster)Set whether |
static void |
@ReplaceWith(expression = "view.setLabelFor(labeledId)")This method is deprecated. Call |
static void |
@ReplaceWith(expression = "view.setLayerPaint(paint)")This method is deprecated. Call |
static void |
@ReplaceWith(expression = "view.setLayerType(layerType, paint)")This method is deprecated. Use |
static void |
@ReplaceWith(expression = "view.setLayoutDirection(layoutDirection)")This method is deprecated. Call |
static void |
setNestedScrollingEnabled(@NonNull View view, boolean enabled)Enable or disable nested scrolling for this view. |
static void |
setNextClusterForwardId(@NonNull View view, int nextClusterForwardId)Sets the ID of the next keyboard navigation cluster root view. |
static void |
setOnApplyWindowInsetsListener(Set an |
static void |
setOnReceiveContentListener(Sets the listener to be used to handle insertion of content into the given view. |
static void |
@ReplaceWith(expression = "view.setOverScrollMode(overScrollMode)")This method is deprecated. Call |
static void |
@ReplaceWith(expression = "view.setPaddingRelative(start, top, end, bottom)")This method is deprecated. Call |
static void |
@ReplaceWith(expression = "view.setPivotX(value)")This method is deprecated. Use |
static void |
@ReplaceWith(expression = "view.setPivotY(value)")This method is deprecated. Use |
static void |
setPointerIcon(@NonNull View view, @Nullable PointerIconCompat pointerIcon)Set the pointer icon for the current view. |
static void |
@ReplaceWith(expression = "view.setRotation(value)")This method is deprecated. Use |
static void |
@ReplaceWith(expression = "view.setRotationX(value)")This method is deprecated. Use |
static void |
@ReplaceWith(expression = "view.setRotationY(value)")This method is deprecated. Use |
static void |
@ReplaceWith(expression = "view.setSaveFromParentEnabled(enabled)")This method is deprecated. Use |
static void |
@ReplaceWith(expression = "view.setScaleX(value)")This method is deprecated. Use |
static void |
@ReplaceWith(expression = "view.setScaleY(value)")This method is deprecated. Use |
static void |
@UiThreadSets 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(@NonNull View view, int indicators)Sets the state of all scroll indicators. |
static void |
setScrollIndicators(@NonNull View view, int indicators, int mask)Sets the state of the scroll indicators specified by the mask. |
static void |
@UiThreadSets the state description of this node. |
static void |
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(@NonNull View view, @Nullable CharSequence tooltipText)Sets the tooltip for the view. |
static void |
setTransitionName(@NonNull View view, @Nullable String transitionName)Sets the name of the View to be used to identify Views in Transitions. |
static void |
@ReplaceWith(expression = "view.setTranslationX(value)")This method is deprecated. Use |
static void |
@ReplaceWith(expression = "view.setTranslationY(value)")This method is deprecated. Use |
static void |
setTranslationZ(@NonNull View view, float translationZ)Sets the depth location of this view relative to its |
static void |
setWindowInsetsAnimationCallback(Sets a |
static void |
@ReplaceWith(expression = "view.setX(value)")This method is deprecated. Use |
static void |
@ReplaceWith(expression = "view.setY(value)")This method is deprecated. Use |
static void |
Sets the visual z position of this view, in pixels. |
static boolean |
startDragAndDrop(Start the drag and drop operation. |
static boolean |
startNestedScroll(@NonNull View view, int axes)Begin a nestable scroll operation along the given axes. |
static boolean |
startNestedScroll(@NonNull View view, int axes, int type)Begin a nestable scroll operation along the given axes. |
static void |
stopNestedScroll(@NonNull View view)Stop a nested scroll in progress. |
static void |
stopNestedScroll(@NonNull View view, int type)Stop a nested scroll in progress. |
static void |
transformMatrixToGlobal(@NonNull View view, @NonNull Matrix matrix)Modifies the input matrix such that it maps on-screen coordinates to view-local coordinates for the provided view. |
static void |
updateDragShadow(Update the drag shadow while drag and drop is in progress. |
Constants
ACCESSIBILITY_LIVE_REGION_ASSERTIVE
public static final int ACCESSIBILITY_LIVE_REGION_ASSERTIVE = 2
Live region mode specifying that accessibility services should interrupt ongoing speech to immediately announce changes to this view.
Use with setAccessibilityLiveRegion.
ACCESSIBILITY_LIVE_REGION_NONE
public static final int ACCESSIBILITY_LIVE_REGION_NONE = 0
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.
ACCESSIBILITY_LIVE_REGION_POLITE
public static final int ACCESSIBILITY_LIVE_REGION_POLITE = 1
Live region mode specifying that accessibility services should announce changes to this view.
Use with setAccessibilityLiveRegion.
public static final int IMPORTANT_FOR_ACCESSIBILITY_AUTO = 0
Automatically determine whether a view is important for accessibility.
public static final int IMPORTANT_FOR_ACCESSIBILITY_NO = 2
The view is not important for accessibility.
public static final int IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS = 4
The view is not important for accessibility, nor are any of its descendant views.
public static final int IMPORTANT_FOR_ACCESSIBILITY_YES = 1
The view is important for accessibility.
IMPORTANT_FOR_CONTENT_CAPTURE_AUTO
public static final int IMPORTANT_FOR_CONTENT_CAPTURE_AUTO = 0
Automatically determine whether a view is important for content capture.
IMPORTANT_FOR_CONTENT_CAPTURE_NO
public static final int IMPORTANT_FOR_CONTENT_CAPTURE_NO = 2
The view is not important for content capture, but its children (if any) will be traversed.
IMPORTANT_FOR_CONTENT_CAPTURE_NO_EXCLUDE_DESCENDANTS
public static final int IMPORTANT_FOR_CONTENT_CAPTURE_NO_EXCLUDE_DESCENDANTS = 8
The view is not important for content capture, and its children (if any) will not be traversed.
IMPORTANT_FOR_CONTENT_CAPTURE_YES
public static final int IMPORTANT_FOR_CONTENT_CAPTURE_YES = 1
The view is important for content capture, and its children (if any) will be traversed.
IMPORTANT_FOR_CONTENT_CAPTURE_YES_EXCLUDE_DESCENDANTS
public static final int IMPORTANT_FOR_CONTENT_CAPTURE_YES_EXCLUDE_DESCENDANTS = 4
The view is important for content capture, but its children (if any) will not be traversed.
public static final int LAYER_TYPE_HARDWARE = 2
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.
public static final int LAYER_TYPE_SOFTWARE = 1
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.)
public static final int LAYOUT_DIRECTION_INHERIT = 2
Horizontal layout direction of this view is inherited from its parent. Use with setLayoutDirection.
public static final int LAYOUT_DIRECTION_LOCALE = 3
Horizontal layout direction of this view is from deduced from the default language script for the locale. Use with setLayoutDirection.
public static final int LAYOUT_DIRECTION_LTR = 0
Horizontal layout direction of this view is from Left to Right.
public static final int LAYOUT_DIRECTION_RTL = 1
Horizontal layout direction of this view is from Right to Left.
public static final int MEASURED_HEIGHT_STATE_SHIFT = 16
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.
public static final int MEASURED_SIZE_MASK = 16777215
Bits of getMeasuredWidthAndState and getMeasuredWidthAndState that provide the actual measured size.
public static final int MEASURED_STATE_MASK = -16777216
Bits of getMeasuredWidthAndState and getMeasuredWidthAndState that provide the additional state bits.
public static final int MEASURED_STATE_TOO_SMALL = 16777216
Bit of getMeasuredWidthAndState and getMeasuredWidthAndState that indicates the measured size is smaller that the space the view would like to have.
public static final int OVER_SCROLL_ALWAYS = 0
Always allow a user to over-scroll this view, provided it is a view that can scroll.
public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1
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.
SCROLL_AXIS_HORIZONTAL
public static final int SCROLL_AXIS_HORIZONTAL = 1
Indicates scrolling along the horizontal axis.
SCROLL_AXIS_NONE
public static final int SCROLL_AXIS_NONE = 0
Indicates no axis of view scrolling.
SCROLL_AXIS_VERTICAL
public static final int SCROLL_AXIS_VERTICAL = 2
Indicates scrolling along the vertical axis.
SCROLL_INDICATOR_BOTTOM
public static final int SCROLL_INDICATOR_BOTTOM = 2
Scroll indicator direction for the bottom edge of the view.
SCROLL_INDICATOR_END
public static final int SCROLL_INDICATOR_END = 32
Scroll indicator direction for the ending edge of the view.
SCROLL_INDICATOR_LEFT
public static final int SCROLL_INDICATOR_LEFT = 4
Scroll indicator direction for the left edge of the view.
SCROLL_INDICATOR_RIGHT
public static final int SCROLL_INDICATOR_RIGHT = 8
Scroll indicator direction for the right edge of the view.
SCROLL_INDICATOR_START
public static final int SCROLL_INDICATOR_START = 16
Scroll indicator direction for the starting edge of the view.
SCROLL_INDICATOR_TOP
public static final int SCROLL_INDICATOR_TOP = 1
Scroll indicator direction for the top edge of the view.
TYPE_NON_TOUCH
public static final int TYPE_NON_TOUCH = 1
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.
TYPE_TOUCH
public static final int TYPE_TOUCH = 0
Indicates that the input type for the gesture is from a user touching the screen.
Protected constructors
Public methods
addAccessibilityAction
public static int addAccessibilityAction(
@NonNull View view,
@NonNull CharSequence label,
@NonNull 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 | |
|---|---|
@NonNull View view |
The view. |
@NonNull CharSequence label |
The user facing description of the action. If an action with the same label already exists, it will be replaced. |
@NonNull AccessibilityViewCommand command |
The command performed when the service requests the action. |
| Returns | |
|---|---|
int |
The id associated with the action, or Compatibility:
|
addKeyboardNavigationClusters
public static void addKeyboardNavigationClusters(
@NonNull View view,
@NonNull 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 | |
|---|---|
@NonNull View view |
view on which to make the change. |
@NonNull Collection<View> views |
collection of keyboard navigation cluster roots found so far. |
int direction |
direction to look. |
addOnUnhandledKeyEventListener
public static void addOnUnhandledKeyEventListener(
@NonNull View view,
@NonNull ViewCompat.OnUnhandledKeyEventListenerCompat listener
)
Adds a listener which will receive unhandled KeyEvents. This must be called on the UI thread.
| Parameters | |
|---|---|
@NonNull View view |
view on which to add the listener. |
@NonNull ViewCompat.OnUnhandledKeyEventListenerCompat listener |
a receiver of unhandled |
| See also | |
|---|---|
removeOnUnhandledKeyEventListener |
addOverlayView
public static void addOverlayView(@NonNull ViewGroup overlayHost, @NonNull View overlay)
Convenience method to add overlay to overlayHost's overlay and assign the disjointParent in the overlay hierarchy.
| Parameters | |
|---|---|
@NonNull ViewGroup overlayHost |
The view to add an overlay to |
@NonNull View overlay |
The view to overlay onto |
| See also | |
|---|---|
add |
public static @NonNull ViewPropertyAnimatorCompatanimate(@NonNull View view)
This method returns a ViewPropertyAnimator object, which can be used to animate specific properties on this View.
| Returns | |
|---|---|
@NonNull ViewPropertyAnimatorCompat |
ViewPropertyAnimator The ViewPropertyAnimator associated with this View. |
@ReplaceWith(expression = "view.canScrollHorizontally(direction)")
public static booleancanScrollHorizontally(View view, int direction)
Check if this view can be scrolled horizontally in a certain direction.
| Parameters | |
|---|---|
View view |
The View against which to invoke the method. |
int direction |
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. |
@ReplaceWith(expression = "view.canScrollVertically(direction)")
public static booleancanScrollVertically(View view, int direction)
Check if this view can be scrolled vertically in a certain direction.
| Parameters | |
|---|---|
View view |
The View against which to invoke the method. |
int direction |
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(@NonNull View v)
Cancel the drag and drop operation.
public static int combineMeasuredStates(int curState, int newState)Merge two states as returned by getMeasuredState.
| Parameters | |
|---|---|
int curState |
The current state as returned from a view or the result of combining multiple views. |
int newState |
The new view state to combine. |
| Returns | |
|---|---|
int |
Returns a new integer reflecting the combination of the two states. |
computeSystemWindowInsets
public static @NonNull WindowInsetsCompat computeSystemWindowInsets(
@NonNull View view,
@NonNull WindowInsetsCompat insets,
@NonNull Rect outLocalInsets
)
Compute insets that should be consumed by this view and the ones that should propagate to those under it.
| Parameters | |
|---|---|
@NonNull View view |
view for which insets need to be computed. |
@NonNull WindowInsetsCompat insets |
Insets currently being processed by this View, likely received as a parameter to |
@NonNull Rect outLocalInsets |
A Rect that will receive the insets that should be consumed by this view |
| Returns | |
|---|---|
@NonNull WindowInsetsCompat |
Insets that should be passed along to views under this one |
dispatchApplyWindowInsets
public static @NonNull WindowInsetsCompat dispatchApplyWindowInsets(
@NonNull View view,
@NonNull 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 | |
|---|---|
@NonNull View view |
view for which to dispatch the request. |
@NonNull WindowInsetsCompat insets |
Insets to apply |
| Returns | |
|---|---|
@NonNull WindowInsetsCompat |
The provided insets minus the insets that were consumed |
dispatchFinishTemporaryDetach
public static void dispatchFinishTemporaryDetach(@NonNull View view)
Notify a view that its temporary detach has ended; the view is now reattached.
dispatchNestedFling
public static boolean dispatchNestedFling(
@NonNull 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 | |
|---|---|
@NonNull View view |
view for which to dispatch the fling. |
float velocityX |
Horizontal fling velocity in pixels per second |
float velocityY |
Vertical fling velocity in pixels per second |
boolean consumed |
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(
@NonNull 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 | |
|---|---|
@NonNull View view |
view for which to dispatch the fling. |
float velocityX |
Horizontal fling velocity in pixels per second |
float velocityY |
Vertical fling velocity in pixels per second |
| Returns | |
|---|---|
boolean |
true if a nested scrolling parent consumed the fling |
dispatchNestedPreScroll
public static boolean dispatchNestedPreScroll(
@NonNull View view,
int dx,
int dy,
@Nullable int[] consumed,
@Nullable 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 using the touch input type.
| Parameters | |
|---|---|
@NonNull View view |
view for which to dispatch the scroll. |
int dx |
Horizontal scroll distance in pixels |
int dy |
Vertical scroll distance in pixels |
@Nullable int[] consumed |
Output. If not null, consumed[0] will contain the consumed component of dx and consumed[1] the consumed dy. |
@Nullable int[] offsetInWindow |
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 |
dispatchNestedPreScroll
public static boolean dispatchNestedPreScroll(
@NonNull View view,
int dx,
int dy,
@Nullable int[] consumed,
@Nullable 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 | |
|---|---|
@NonNull View view |
view for which to dispatch the scroll. |
int dx |
Horizontal scroll distance in pixels |
int dy |
Vertical scroll distance in pixels |
@Nullable int[] consumed |
Output. If not null, consumed[0] will contain the consumed component of dx and consumed[1] the consumed dy. |
@Nullable int[] offsetInWindow |
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. |
int type |
the type of input which cause this scroll event |
| Returns | |
|---|---|
boolean |
true if the parent consumed some or all of the scroll delta |
| See also | |
|---|---|
dispatchNestedScroll |
dispatchNestedScroll
public static boolean dispatchNestedScroll(
@NonNull View view,
int dxConsumed,
int dyConsumed,
int dxUnconsumed,
int dyUnconsumed,
@Nullable int[] offsetInWindow
)
Dispatch one step of a nested scroll in progress.
This version of the method just calls dispatchNestedScroll using the touch input type.
| Parameters | |
|---|---|
@NonNull View view |
view for which to dispatch the scroll. |
int dxConsumed |
Horizontal distance in pixels consumed by this view during this scroll step |
int dyConsumed |
Vertical distance in pixels consumed by this view during this scroll step |
int dxUnconsumed |
Horizontal scroll distance in pixels not consumed by this view |
int dyUnconsumed |
Horizontal scroll distance in pixels not consumed by this view |
@Nullable int[] offsetInWindow |
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 boolean dispatchNestedScroll(
@NonNull View view,
int dxConsumed,
int dyConsumed,
int dxUnconsumed,
int dyUnconsumed,
@Nullable 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 | |
|---|---|
@NonNull View view |
view for which to dispatch the scroll. |
int dxConsumed |
Horizontal distance in pixels consumed by this view during this scroll step |
int dyConsumed |
Vertical distance in pixels consumed by this view during this scroll step |
int dxUnconsumed |
Horizontal scroll distance in pixels not consumed by this view |
int dyUnconsumed |
Horizontal scroll distance in pixels not consumed by this view |
@Nullable int[] offsetInWindow |
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. |
int type |
the type of input which cause this scroll event |
| Returns | |
|---|---|
boolean |
true if the event was dispatched, and therefore the scroll distance was consumed |
| See also | |
|---|---|
dispatchNestedPreScroll |
dispatchNestedScroll
public static void dispatchNestedScroll(
@NonNull View view,
int dxConsumed,
int dyConsumed,
int dxUnconsumed,
int dyUnconsumed,
@Nullable int[] offsetInWindow,
int type,
@NonNull 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 | |
|---|---|
@NonNull View view |
view for which to dispatch the scroll. |
int dxConsumed |
Horizontal distance in pixels consumed by this view during this scroll step |
int dyConsumed |
Vertical distance in pixels consumed by this view during this scroll step |
int dxUnconsumed |
Horizontal scroll distance in pixels not consumed by this view |
int dyUnconsumed |
Horizontal scroll distance in pixels not consumed by this view |
@Nullable int[] offsetInWindow |
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. |
int type |
the type of input which cause this scroll event |
@NonNull int[] consumed |
Output, If not null, |
dispatchStartTemporaryDetach
public static void dispatchStartTemporaryDetach(@NonNull View view)
Notify a view that it is being temporarily detached.
enableAccessibleClickableSpanSupport
public static void enableAccessibleClickableSpanSupport(@NonNull View view)
Allow accessibility services to find and activate clickable spans in the application.
android.text.style.ClickableSpan is automatically supported from API 26. For compatibility back to API 19, this should be enabled.
android.text.style.URLSpan, a subclass of ClickableSpans, is automatically supported and does not need this enabled.
Do not put ClickableSpans in setContentDescription or setStateDescription. These links are only visible to accessibility services in getText, which should be modifiable using helper methods on UI elements. For example, use setText to modify the text of TextViews.
public static int generateViewId()Generate a value suitable for use in setId. 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 @Nullable AccessibilityDelegateCompat getAccessibilityDelegate(@NonNull View view)
Get the current accessibility delegate.
| Returns | |
|---|---|
@Nullable 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 |
| See also | |
|---|---|
setAccessibilityDelegate |
@ReplaceWith(expression = "view.getAccessibilityLiveRegion()")
public static intgetAccessibilityLiveRegion(@NonNull View view)
Gets the live region mode for the specified View.
| Returns | |
|---|---|
int |
The live region mode for the view. |
| See also | |
|---|---|
setAccessibilityLiveRegion |
getAccessibilityNodeProvider
public static @Nullable AccessibilityNodeProviderCompat getAccessibilityNodeProvider(@NonNull View view)
Gets the provider for managing a virtual view hierarchy rooted at this View and reported to android.accessibilityservice.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 its getAccessibilityNodeProvider is responsible for handling this call.
| Returns | |
|---|---|
@Nullable AccessibilityNodeProviderCompat |
The provider. |
| See also | |
|---|---|
AccessibilityNodeProviderCompat |
getAccessibilityPaneTitle
@UiThread
public static @Nullable CharSequence getAccessibilityPaneTitle(@NonNull View view)
Get the title of the pane for purposes of accessibility.
| Parameters | |
|---|---|
@NonNull View view |
The view queried for it's pane title. Compatibility:
|
| Returns | |
|---|---|
@Nullable CharSequence |
The current pane title. {@see #setAccessibilityPaneTitle}. |
@ReplaceWith(expression = "view.getAlpha()")
public static floatgetAlpha(View view)
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. |
getAutofillId
public static @Nullable AutofillIdCompat getAutofillId(@NonNull View v)
Gets the unique, logical identifier of this view in the activity, for autofill purposes.
The autofill id is created on demand, unless it is explicitly set by setAutofillId.
See setAutofillId for more info. Compatibility behavior:
- SDK 26 and above, this method matches platform behavior.
- SDK 25 and below, this method always return null.
| Returns | |
|---|---|
@Nullable AutofillIdCompat |
The View's autofill id. |
getBackgroundTintList
public static @Nullable ColorStateList getBackgroundTintList(@NonNull 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.
getBackgroundTintMode
public static @Nullable PorterDuff.Mode getBackgroundTintMode(@NonNull 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.
@ReplaceWith(expression = "view.getClipBounds()")
public static @Nullable RectgetClipBounds(@NonNull View view)
Returns a copy of the current setClipBounds.
Prior to API 18 this will return null.
getContentCaptureSession
public static @Nullable ContentCaptureSessionCompat getContentCaptureSession(@NonNull View v)
Gets the session used to notify content capture events. Compatibility behavior:
- SDK 29 and above, this method matches platform behavior.
- SDK 28 and below, this method always return null.
| Returns | |
|---|---|
@Nullable ContentCaptureSessionCompat |
session explicitly set by setContentCaptureSession, inherited by ancestors, default session or |
@ReplaceWith(expression = "view.getDisplay()")
public static @Nullable DisplaygetDisplay(@NonNull 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.
getElevation
public static float getElevation(@NonNull View view)
The base elevation of this view relative to its parent, in pixels.
| Returns | |
|---|---|
float |
The base depth position of the view, in pixels. |
@ReplaceWith(expression = "view.getFitsSystemWindows()")
public static booleangetFitsSystemWindows(@NonNull View view)
Returns true if this view should adapt to fit system window insets. This method will always return false before API 16 (Jellybean).
@ReplaceWith(expression = "view.getImportantForAccessibility()")
public static intgetImportantForAccessibility(@NonNull 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.
| Returns | |
|---|---|
int |
The mode for determining whether a View is important for accessibility. |
getImportantForAutofill
public static int getImportantForAutofill(@NonNull View v)
Gets the mode for determining whether this view is important for autofill.
See setImportantForAutofill and isImportantForAutofill for more info about this mode.
This method is only supported on API >= 26. On API 25 and below, it will always return IMPORTANT_FOR_AUTOFILL_AUTO.
| Returns | |
|---|---|
int |
|
getImportantForContentCapture
public static int getImportantForContentCapture(@NonNull View v)
Gets the mode for determining whether this view is important for content capture.
See setImportantForContentCapture and isImportantForContentCapture for more info about this mode. Compatibility behavior:
- SDK 30 and above, this method matches platform behavior.
- SDK 29 and below, this method always return
IMPORTANT_FOR_CONTENT_CAPTURE_AUTO.
ref android.R.styleable#View_importantForContentCapture
| Returns | |
|---|---|
int |
|
@ReplaceWith(expression = "view.getLabelFor()")
public static intgetLabelFor(@NonNull View view)
Gets the id of a view for which a given view serves as a label for accessibility purposes.
| Returns | |
|---|---|
int |
The labeled view id. |
@ReplaceWith(expression = "view.getLayerType()")
public static intgetLayerType(View view)
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 for more information on the different types of layers.
| Parameters | |
|---|---|
View view |
The view to fetch the layer type from |
| Returns | |
|---|---|
int |
@ReplaceWith(expression = "view.getLayoutDirection()")
public static intgetLayoutDirection(@NonNull View view)
Returns the resolved layout direction for this view.
| Returns | |
|---|---|
int |
|
@ReplaceWith(expression = "view.getMatrix()")
public static @Nullable MatrixgetMatrix(View view)
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 |
| See also | |
|---|---|
getRotation |
|
getScaleX |
|
getScaleY |
|
getPivotX |
|
getPivotY |
@ReplaceWith(expression = "view.getMeasuredHeightAndState()")
public static intgetMeasuredHeightAndState(View view)
Return the full height measurement information for this view as computed by the most recent call to measure. 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. |
@ReplaceWith(expression = "view.getMeasuredState()")
public static intgetMeasuredState(View view)
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.
@ReplaceWith(expression = "view.getMeasuredWidthAndState()")
public static intgetMeasuredWidthAndState(View view)
Return the full width measurement information for this view as computed by the most recent call to measure. 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. |
@ReplaceWith(expression = "view.getMinimumHeight()")
public static intgetMinimumHeight(@NonNull View view)
Returns the minimum height of the view.
Prior to API 16, this method may return 0 on some platforms.
| Returns | |
|---|---|
int |
the minimum height the view will try to be. |
@ReplaceWith(expression = "view.getMinimumWidth()")
public static intgetMinimumWidth(@NonNull View view)
Returns the minimum width of the view.
Prior to API 16, this method may return 0 on some platforms.
| Returns | |
|---|---|
int |
the minimum width the view will try to be. |
getNextClusterForwardId
public static int getNextClusterForwardId(@NonNull View view)
Gets the ID of the next keyboard navigation cluster root.
| Returns | |
|---|---|
int |
the next keyboard navigation cluster ID, or |
getOnReceiveContentMimeTypes
public static @Nullable String[] getOnReceiveContentMimeTypes(@NonNull View view)
Returns the MIME types accepted by the listener configured on the given view via setOnReceiveContentListener. 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 compareMimeTypes 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 normalizeMimeType to ensure that it is converted to lowercase.
| Returns | |
|---|---|
@Nullable String[] |
The MIME types accepted by the |
@ReplaceWith(expression = "view.getOverScrollMode()")
public static intgetOverScrollMode(View view)
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 | |
|---|---|
View view |
The View against which to invoke the method. |
| Returns | |
|---|---|
int |
This view's over-scroll mode. |
@ReplaceWith(expression = "view.getPaddingEnd()")
public static @Px intgetPaddingEnd(@NonNull 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.
| Returns | |
|---|---|
@Px int |
the end padding in pixels |
@ReplaceWith(expression = "view.getPaddingStart()")
public static @Px intgetPaddingStart(@NonNull 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.
| Returns | |
|---|---|
@Px int |
the start padding in pixels |
@ReplaceWith(expression = "view.getParentForAccessibility()")
public static @Nullable ViewParentgetParentForAccessibility(@NonNull 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.
| Returns | |
|---|---|
@Nullable ViewParent |
The parent for use in accessibility inspection |
@ReplaceWith(expression = "view.getPivotX()")
public static floatgetPivotX(View view)
The x location of the point around which the view is rotated and scaled.
| Parameters | |
|---|---|
View view |
view for which to get the pivot. |
@ReplaceWith(expression = "view.getPivotY()")
public static floatgetPivotY(View view)
The y location of the point around which the view is rotated and scaled.
| Parameters | |
|---|---|
View view |
view for which to get the pivot. |
| Returns | |
|---|---|
float |
The y location of the pivot point. |
getRootWindowInsets
public static @Nullable WindowInsetsCompat getRootWindowInsets(@NonNull 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 20 and below, this method always returns null.
| Returns | |
|---|---|
@Nullable WindowInsetsCompat |
WindowInsetsCompat from the top of the view hierarchy or null if View is detached |
@ReplaceWith(expression = "view.getRotation()")
public static floatgetRotation(View view)
| Parameters | |
|---|---|
View view |
view for which to get the rotation. |
@ReplaceWith(expression = "view.getRotationX()")
public static floatgetRotationX(View view)
| Parameters | |
|---|---|
View view |
view for which to get the rotation. |
@ReplaceWith(expression = "view.getRotationY()")
public static floatgetRotationY(View view)
| Parameters | |
|---|---|
View view |
view for which to get the rotation. |
@ReplaceWith(expression = "view.getScaleX()")
public static floatgetScaleX(View view)
| Parameters | |
|---|---|
View view |
view for which to get the scale. |
@ReplaceWith(expression = "view.getScaleY()")
public static floatgetScaleY(View view)
| Parameters | |
|---|---|
View view |
view for which to get the scale. |
getScrollIndicators
public static int getScrollIndicators(@NonNull 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.
| Returns | |
|---|---|
int |
a bitmask representing the enabled scroll indicators |
getStateDescription
@UiThread
public static @Nullable CharSequence getStateDescription(@NonNull 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 to modify the state description.
| Returns | |
|---|---|
@Nullable CharSequence |
the state description |
| See also | |
|---|---|
setStateDescription |
getSystemGestureExclusionRects
public static @NonNull List<Rect> getSystemGestureExclusionRects(@NonNull 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.
| See also | |
|---|---|
getSystemGestureExclusionRects |
getTransitionName
public static @Nullable String getTransitionName(@NonNull 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.
@ReplaceWith(expression = "view.getTranslationX()")
public static floatgetTranslationX(View view)
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. |
@ReplaceWith(expression = "view.getTranslationY()")
public static floatgetTranslationY(View view)
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
public static float getTranslationZ(@NonNull View view)
The depth location of this view relative to its elevation.
| Returns | |
|---|---|
float |
The depth of this view relative to its elevation. |
public static @Nullable WindowInsetsControllerCompatgetWindowInsetsController(@NonNull View view)
Retrieves a WindowInsetsControllerCompat of the window this view is attached to.
| Returns | |
|---|---|
@Nullable WindowInsetsControllerCompat |
A |
| See also | |
|---|---|
getInsetsController |
@ReplaceWith(expression = "view.getWindowSystemUiVisibility()")
public static intgetWindowSystemUiVisibility(@NonNull View view)
Returns the current system UI visibility that is currently set for the entire window.
@ReplaceWith(expression = "view.getX()")
public static floatgetX(View view)
| Parameters | |
|---|---|
View view |
view for which to get the X. |
@ReplaceWith(expression = "view.getY()")
public static floatgetY(View view)
| Parameters | |
|---|---|
View view |
view for which to get the Y. |
getZ
public static float getZ(@NonNull View view)
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. |
hasAccessibilityDelegate
public static boolean hasAccessibilityDelegate(@NonNull View view)
Checks whether provided View has an accessibility delegate attached to it.
| Returns | |
|---|---|
boolean |
True if the View has an accessibility delegate |
hasExplicitFocusable
public static boolean hasExplicitFocusable(@NonNull View view)
Returns true if this view is focusable or if it contains a reachable View for which hasExplicitFocusable returns true. A "reachable hasExplicitFocusable()" is a view whose parents do not block descendants focus. Only VISIBLE views for which getFocusable would return FOCUSABLE are considered focusable.
This method preserves the pre-O behavior of hasFocusable in that only views explicitly set focusable will cause this method to return true. A view set to FOCUSABLE_AUTO that resolves to focusable will not.
| Returns | |
|---|---|
boolean |
|
hasNestedScrollingParent
public static boolean hasNestedScrollingParent(@NonNull View view)
Returns true if this view has a nested scrolling parent.
This version of the method just calls hasNestedScrollingParent using the touch input type.
| Returns | |
|---|---|
boolean |
whether this view has a nested scrolling parent |
hasNestedScrollingParent
public static boolean hasNestedScrollingParent(@NonNull 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 | |
|---|---|
@NonNull View view |
view for which to check the parent. |
int type |
the type of input which cause this scroll event |
| Returns | |
|---|---|
boolean |
whether this view has a nested scrolling parent |
@ReplaceWith(expression = "view.hasOnClickListeners()")
public static booleanhasOnClickListeners(@NonNull View view)
Returns whether the provided view has an attached View.OnClickListener.
| Returns | |
|---|---|
boolean |
true if there is a listener, false if there is none. |
@ReplaceWith(expression = "view.hasOverlappingRendering()")
public static booleanhasOverlappingRendering(@NonNull 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.
| Returns | |
|---|---|
boolean |
true if the content in this view might overlap, false otherwise. |
@ReplaceWith(expression = "view.hasTransientState()")
public static booleanhasTransientState(@NonNull 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.
| Returns | |
|---|---|
boolean |
true if the view has transient state |
isAccessibilityHeading
@UiThread
public static boolean isAccessibilityHeading(@NonNull View view)
Gets whether this view is a heading for accessibility purposes.
| Parameters | |
|---|---|
@NonNull View view |
The view checked if it is a heading. Compatibility:
|
| Returns | |
|---|---|
boolean |
|
@ReplaceWith(expression = "view.isAttachedToWindow()")
public static booleanisAttachedToWindow(@NonNull View view)
Returns true if the provided view is currently attached to a window.
isFocusedByDefault
public static boolean isFocusedByDefault(@NonNull 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.
| Returns | |
|---|---|
boolean |
|
isImportantForAccessibility
public static boolean isImportantForAccessibility(@NonNull 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 value:
IMPORTANT_FOR_ACCESSIBILITY_NOorIMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS, returnfalseIMPORTANT_FOR_ACCESSIBILITY_YES, returntrueIMPORTANT_FOR_ACCESSIBILITY_AUTO, returntrueif view satisfies any of the following:- Is actionable, e.g.
isClickable,isLongClickable, orisFocusable - Has an
AccessibilityDelegateCompat - Has an interaction listener, e.g.
View.OnTouchListener,View.OnKeyListener, etc. - Is an accessibility live region, e.g.
getAccessibilityLiveRegionis notACCESSIBILITY_LIVE_REGION_NONE.
Note: Prior to API 21, this method will always return true.
| Returns | |
|---|---|
boolean |
Whether the view is exposed for accessibility. |
isImportantForAutofill
public static boolean isImportantForAutofill(@NonNull View v)
Hints the Android System whether the android.app.assist.AssistStructure.ViewNode associated with this view is considered important for autofill purposes.
Generally speaking, a view is important for autofill if:
- The view can be autofilled by an
android.service.autofill.AutofillService. - The view contents can help an
android.service.autofill.AutofillServicedetermine 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:
- if it returns
IMPORTANT_FOR_AUTOFILL_YESorIMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS, then it returnstrue - if it returns
IMPORTANT_FOR_AUTOFILL_NOorIMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS, then it returnsfalse - if it returns
IMPORTANT_FOR_AUTOFILL_AUTO, then it uses some simple heuristics that can returntruein some cases (like a container with a resource id), butfalsein most. - otherwise, it returns
false.
When a view is considered important for autofill:
- The view might automatically trigger an autofill request when focused on.
- The contents of the view are included in the
android.view.ViewStructureused in an autofill request.
On the other hand, when a view is considered not important for autofill:
- The view never automatically triggers autofill requests, but it can trigger a manual request through
requestAutofill. - The contents of the view are not included in the
android.view.ViewStructureused in an autofill request, unless the request has theAUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWSflag.
This method is only supported on API >= 26. On API 25 and below, it will always return true.
| Returns | |
|---|---|
boolean |
whether the view is considered important for autofill. |
isImportantForContentCapture
public static boolean isImportantForContentCapture(@NonNull View v)
Hints the Android System whether this view is considered important for content capture, based on the value explicitly set by setImportantForContentCapture and heuristics when it's IMPORTANT_FOR_CONTENT_CAPTURE_AUTO.
See ContentCaptureManager for more info about content capture. Compatibility behavior:
- SDK 30 and above, this method matches platform behavior.
- SDK 29 and below, this method always return false.
| Returns | |
|---|---|
boolean |
whether the view is considered important for content capture. |
@ReplaceWith(expression = "view.isInLayout()")
public static booleanisInLayout(@NonNull View view)
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.
Compatibility:
- API <18: Always returns
false
| Returns | |
|---|---|
boolean |
whether the view hierarchy is currently undergoing a layout pass |
isKeyboardNavigationCluster
public static boolean isKeyboardNavigationCluster(@NonNull View view)
Returns whether view is a root of a keyboard navigation cluster. Always returns false on API <26.
| Returns | |
|---|---|
boolean |
|
@ReplaceWith(expression = "view.isLaidOut()")
public static booleanisLaidOut(@NonNull View view)
Returns true if view has been through at least one layout since it was last attached to or detached from a window.
@ReplaceWith(expression = "view.isLayoutDirectionResolved()")
public static booleanisLayoutDirectionResolved(@NonNull View view)
Returns whether layout direction has been resolved.
Compatibility:
- API <19: Always returns
false
| Returns | |
|---|---|
boolean |
true if layout direction has been resolved. |
isNestedScrollingEnabled
public static boolean isNestedScrollingEnabled(@NonNull View view)
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 | |
|---|---|
setNestedScrollingEnabled |
@ReplaceWith(expression = "view.isOpaque()")
public static booleanisOpaque(View view)
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.
| Parameters | |
|---|---|
View view |
view for which to check the state. |
| Returns | |
|---|---|
boolean |
True if this View is guaranteed to be fully opaque, false otherwise. |
@ReplaceWith(expression = "view.isPaddingRelative()")
public static booleanisPaddingRelative(@NonNull View view)
Return if the padding as been set through relative values View.setPaddingRelative(int, int, int, int) or thru
| Returns | |
|---|---|
boolean |
true if the padding is relative or false if it is not. |
isScreenReaderFocusable
@UiThread
public static boolean isScreenReaderFocusable(@NonNull View view)
Returns whether the view should be treated as a focusable unit by screen reader accessibility tools.
| Parameters | |
|---|---|
@NonNull View view |
The view to check for screen reader focusability. Compatibility:
|
| Returns | |
|---|---|
boolean |
Whether the view should be treated as a focusable unit by screen reader. |
| See also | |
|---|---|
setScreenReaderFocusable |
@ReplaceWith(expression = "view.jumpDrawablesToCurrentState()")
public static voidjumpDrawablesToCurrentState(View view)
On API 11 devices and above, call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.
On API 21 and above, also calls StateListAnimator#jumpToCurrentState() if there is a StateListAnimator attached to this view.
| Parameters | |
|---|---|
View view |
view for which to jump the drawable state. |
keyboardNavigationClusterSearch
public static @Nullable View keyboardNavigationClusterSearch(
@NonNull View view,
@Nullable View currentCluster,
int direction
)
Find the nearest keyboard navigation cluster in the specified direction. This does not actually give focus to that cluster.
offsetLeftAndRight
public static void offsetLeftAndRight(@NonNull View view, int offset)
Offset this view's horizontal location by the specified amount of pixels.
offsetTopAndBottom
public static void offsetTopAndBottom(@NonNull View view, int offset)
Offset this view's vertical location by the specified number of pixels.
onApplyWindowInsets
public static @NonNull WindowInsetsCompat onApplyWindowInsets(@NonNull View view, @NonNull WindowInsetsCompat insets)
Called when the view should apply WindowInsetsCompat according to its internal policy.
Clients may supply an 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.
| Parameters | |
|---|---|
@NonNull View view |
The View against which to invoke the method. |
@NonNull WindowInsetsCompat insets |
Insets to apply |
| Returns | |
|---|---|
@NonNull WindowInsetsCompat |
The supplied insets with any applied insets consumed |
@ReplaceWith(expression = "v.onInitializeAccessibilityEvent(event)")
public static voidonInitializeAccessibilityEvent(View v, 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 AccessibilityDelegateCompat has been specified via calling setAccessibilityDelegate, its onInitializeAccessibilityEvent is responsible for handling this call.
| Parameters | |
|---|---|
View v |
The View against which to invoke the method. |
AccessibilityEvent event |
The event to initialize. |
@ReplaceWith(expression = "v.onInitializeAccessibilityNodeInfo(info.unwrap())")
public static voidonInitializeAccessibilityNodeInfo(
@NonNull View v,
@NonNull AccessibilityNodeInfoCompat info
)
Initializes an AccessibilityNodeInfoCompat with information about this view. The base implementation sets:
setParent,setBoundsInParent,setBoundsInScreen,setPackageName,setClassName,setContentDescription,setStateDescription,setEnabled,setClickable,setFocusable,setFocused,setLongClickable,setSelected,
If an AccessibilityDelegateCompat has been specified via calling setAccessibilityDelegate, its onInitializeAccessibilityNodeInfo method is responsible for handling this call.
| Parameters | |
|---|---|
@NonNull View v |
The View against which to invoke the method. |
@NonNull AccessibilityNodeInfoCompat info |
The instance to initialize. |
@ReplaceWith(expression = "v.onPopulateAccessibilityEvent(event)")
public static voidonPopulateAccessibilityEvent(View v, AccessibilityEvent event)
Called from dispatchPopulateAccessibilityEvent giving a chance to this View to populate the accessibility event with its text content.
Note: This method should only be used with getText. Avoid mutating other event state in this method. Instead, follow the practices described in dispatchPopulateAccessibilityEvent. In general, put UI metadata in the node for services to easily query, than in events.
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 AccessibilityDelegateCompat has been specified via calling setAccessibilityDelegate its onPopulateAccessibilityEvent 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 | |
|---|---|
View v |
The View against which to invoke the method. |
AccessibilityEvent event |
The accessibility event which to populate. |
@ReplaceWith(expression = "view.performAccessibilityAction(action, arguments)")
public static booleanperformAccessibilityAction(
@NonNull View view,
int action,
@Nullable Bundle arguments
)
Performs the specified accessibility action on the view. For possible accessibility actions look at AccessibilityNodeInfoCompat.
If an AccessibilityDelegateCompat has been specified via calling setAccessibilityDelegate its performAccessibilityAction is responsible for handling this call.
Note: Avoid setting accessibility focus with ACTION_ACCESSIBILITY_FOCUS. This is intended to be controlled by screen readers. Apps changing focus can confuse screen readers, and the resulting behavior can vary by device and screen reader version.
| Parameters | |
|---|---|
@NonNull View view |
view on which to perform the action. |
int action |
The action to perform. |
@Nullable Bundle arguments |
Optional action arguments. |
| Returns | |
|---|---|
boolean |
Whether the action was performed. |
performHapticFeedback
public static boolean performHapticFeedback(@NonNull View view, int feedbackConstant)
Perform a haptic feedback to the user for the 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. Note: Check compatibility support for each feedback constant described at HapticFeedbackConstantsCompat.
| Parameters | |
|---|---|
@NonNull View view |
The view. |
int feedbackConstant |
One of the constants defined in |
| Returns | |
|---|---|
boolean |
Whether the feedback might be performed - generally this result should be ignored |
performHapticFeedback
public static boolean performHapticFeedback(@NonNull View view, int feedbackConstant, int flags)
Perform a haptic feedback to the user for the view.
This is similar to performHapticFeedback, with additional options. Note: Check compatibility support for each feedback constant described at HapticFeedbackConstantsCompat.
| Parameters | |
|---|---|
@NonNull View view |
The view. |
int feedbackConstant |
One of the constants defined in |
int flags |
Additional flags as per |
| Returns | |
|---|---|
boolean |
Whether the feedback might be performed - generally this result should be ignored |
performReceiveContent
public static @Nullable ContentInfoCompat performReceiveContent(
@NonNull View view,
@NonNull ContentInfoCompat payload
)
Receives the given content.
If a listener is set, invokes the listener. If the listener returns a non-null result, executes the fallback handling for the portion of the content returned by the listener.
If no listener is set, executes the fallback handling.
The fallback handling is defined by the target view if the view implements OnReceiveContentViewBehavior, or is simply a no-op.
| Parameters | |
|---|---|
@NonNull View view |
The target view. |
@NonNull ContentInfoCompat payload |
The content to insert and related metadata. |
| Returns | |
|---|---|
@Nullable ContentInfoCompat |
The portion of the passed-in content that was not handled (may be all, some, or none of the passed-in content). |
@ReplaceWith(expression = "view.postInvalidateOnAnimation()")
public static voidpostInvalidateOnAnimation(@NonNull View view)
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.
@ReplaceWith(expression = "view.postInvalidateOnAnimation(left, top, right, bottom)")
public static voidpostInvalidateOnAnimation(
@NonNull 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.
This method can be invoked from outside of the UI thread only when this View is attached to a window.
@ReplaceWith(expression = "view.postOnAnimation(action)")
public static voidpostOnAnimation(@NonNull View view, @NonNull Runnable action)
Causes the Runnable to execute on the next animation time step. The runnable will be run on the user interface thread.
This method can be invoked from outside of the UI thread only when this View is attached to a window.
@ReplaceWith(expression = "view.postOnAnimationDelayed(action, delayMillis)")
public static voidpostOnAnimationDelayed(
@NonNull View view,
@NonNull 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.
This method can be invoked from outside of the UI thread only when this View is attached to a window.
removeAccessibilityAction
public static void removeAccessibilityAction(@NonNull View view, int actionId)
Removes an accessibility action that can be performed on a node associated with a view. If the action was not already added to the view, calling this method has no effect.
removeOnUnhandledKeyEventListener
public static void removeOnUnhandledKeyEventListener(
@NonNull View view,
@NonNull ViewCompat.OnUnhandledKeyEventListenerCompat listener
)
Removes a listener which will receive unhandled KeyEvents. This must be called on the UI thread.
| Parameters | |
|---|---|
@NonNull View view |
view from which to remove the listener. |
@NonNull ViewCompat.OnUnhandledKeyEventListenerCompat listener |
a receiver of unhandled |
| See also | |
|---|---|
addOnUnhandledKeyEventListener |
replaceAccessibilityAction
public static void replaceAccessibilityAction(
@NonNull View view,
@NonNull AccessibilityNodeInfoCompat.AccessibilityActionCompat replacedAction,
@Nullable CharSequence label,
@Nullable AccessibilityViewCommand command
)
Replaces an action. This can be used to change the default behavior or label of the action specified. If label and command are both null, the action will be removed.
| Parameters | |
|---|---|
@NonNull View view |
The view. |
@NonNull AccessibilityNodeInfoCompat.AccessibilityActionCompat replacedAction |
The action to be replaced. |
@Nullable CharSequence label |
The user facing description of the action or |
@Nullable AccessibilityViewCommand command |
The command performed when the service requests the action. Compatibility:
|
requestApplyInsets
public static void requestApplyInsets(@NonNull View view)
Ask that a new dispatch of View.onApplyWindowInsets(WindowInsets) be performed. This falls back to View.requestFitSystemWindows() where available.
requireViewById
public static @NonNull T <T extends View> requireViewById(@NonNull View view, @IdRes int id)
Finds the first descendant view with the given ID, the view itself if the ID matches getId, or throws an IllegalArgumentException if the ID is invalid or there is no matching view in the hierarchy.
Note: In most cases -- depending on compiler support -- the resulting view is automatically cast to the target class type. If the target class type is unconstrained, an explicit cast may be necessary.
| Returns | |
|---|---|
@NonNull T |
a view with given ID |
| See also | |
|---|---|
findViewById |
public static 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 | |
|---|---|
int size |
How big the view wants to be |
int measureSpec |
Constraints imposed by the parent |
int childMeasuredState |
Size information bit mask for the view's children. |
| Returns | |
|---|---|
int |
Size information bit mask as defined by |
restoreDefaultFocus
public static boolean restoreDefaultFocus(@NonNull View view)
Gives focus to the default-focus view in the view hierarchy rooted at view. If the default-focus view cannot be found or if API <26, this falls back to calling requestFocus.
| Returns | |
|---|---|
boolean |
|
saveAttributeDataForStyleable
public static void saveAttributeDataForStyleable(
@NonNull View view,
@NonNull Context context,
@NonNull int[] styleable,
@Nullable AttributeSet attrs,
@NonNull TypedArray t,
int defStyleAttr,
int defStyleRes
)
Stores debugging information about attributes. This should be called in a constructor by every custom View that uses a custom styleable. If the custom view does not call it, then the custom attributes used by this view will not be visible in layout inspection tools. No-op before API 29.
| Parameters | |
|---|---|
@NonNull View view |
view for which to save the data. |
@NonNull Context context |
Context under which this view is created. |
@NonNull int[] styleable |
A reference to styleable array R.styleable.Foo |
@Nullable AttributeSet attrs |
AttributeSet used to construct this view. |
@NonNull TypedArray t |
Resolved |
int defStyleAttr |
Default style attribute passed into the view constructor. |
int defStyleRes |
Default style resource passed into the view constructor. |
setAccessibilityDelegate
public static void setAccessibilityDelegate(
@NonNull View v,
@Nullable AccessibilityDelegateCompat delegate
)
Sets a delegate for implementing accessibility support via composition (as opposed to inheritance). For more details, see AccessibilityDelegateCompat.
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, 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.
If an AccessibilityDelegateCompat is already attached to the view, and this method sets the delegate to null, an empty delegate will be attached to ensure that other compatibility behavior continues to work for this view.
| Parameters | |
|---|---|
@NonNull View v |
view for which to set the delegate. |
@Nullable AccessibilityDelegateCompat delegate |
the object to which accessibility method calls should be delegated |
| See also | |
|---|---|
AccessibilityDelegateCompat |
setAccessibilityHeading
@UiThread
public static void setAccessibilityHeading(@NonNull View view, boolean isHeading)
Set if view is a heading for a section of content for accessibility purposes.
@ReplaceWith(expression = "view.setAccessibilityLiveRegion(mode)")
public static voidsetAccessibilityLiveRegion(@NonNull View view, 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).
To indicate that the user should be notified of changes, use ACCESSIBILITY_LIVE_REGION_POLITE. Announcements from this region are queued and do not disrupt ongoing speech.
For example, selecting an option in a dropdown menu may update a panel below with the updated content. This panel may be marked as a live region with ACCESSIBILITY_LIVE_REGION_POLITE to notify users of the change.
For notifying users about errors, such as in a login screen with text that displays an "incorrect password" notification, that view should send an AccessibilityEvent of type CONTENT_CHANGE_TYPE_ERROR and set setError instead. Custom widgets should expose error-setting methods that support accessibility automatically. For example, instead of explicitly sending this event when using a TextView, use setError.
To disable change notifications for this view, use ACCESSIBILITY_LIVE_REGION_NONE. This is the default live region mode for most views.
If the view's changes should interrupt ongoing speech and notify the user immediately, use ACCESSIBILITY_LIVE_REGION_ASSERTIVE. This may result in disruptive announcements from an accessibility service, so it should generally be used only to convey information that is time-sensitive or critical for use of the application. Examples may include an incoming call or an emergency alert.
setAccessibilityPaneTitle
@UiThread
public static void setAccessibilityPaneTitle(
@NonNull View view,
@Nullable CharSequence accessibilityPaneTitle
)
Visually distinct portion of a window with window-like semantics are considered panes for accessibility purposes. One example is the content view of a large fragment that is replaced. In order for accessibility services to understand a pane's window-like behavior, panes should have descriptive titles. Views with pane titles produce TYPE_WINDOW_STATE_CHANGEDs when they appear, disappear, or change title.
When transitioning from one Activity to another, instead of using setAccessibilityPaneTitle(), set a descriptive title for your activity's window by using android:label for the matching entry in your application’s manifest or updating the title at runtime with .
To set the pane title in xml, use android:accessibilityPaneTitle.
| Parameters | |
|---|---|
@NonNull View view |
The view whose pane title should be set. |
@Nullable CharSequence accessibilityPaneTitle |
The pane's title. Setting to Compatibility:
|
@ReplaceWith(expression = "view.setActivated(activated)")
public static voidsetActivated(View view, 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.
| Parameters | |
|---|---|
View view |
view for which to set the state. |
boolean activated |
true if the view must be activated, false otherwise |
@ReplaceWith(expression = "view.setAlpha(value)")
public static voidsetAlpha(View view, @FloatRange(from = 0.0, to = 1.0) float value)
Sets 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.
Note that setting alpha to a translucent value (0 view to set the alpha on. The opacity of the view.
Parameters
View view
@FloatRange(from = 0.0, to = 1.0) float value
setAutofillHints
public static void setAutofillHints(@NonNull View view, @Nullable String[] autofillHints)
Sets the hints that help an android.service.autofill.AutofillService determine how to autofill the view with the user's data.
Typically, there is only one way to autofill a view, but there could be more than one. For example, if the application accepts either an username or email address to identify an user.
These hints are not validated by the Android System, but passed "as is" to the service. Hence, they can have any value, but it's recommended to use the AUTOFILL_HINT_ constants such as: AUTOFILL_HINT_USERNAME, AUTOFILL_HINT_PASSWORD, AUTOFILL_HINT_EMAIL_ADDRESS, AUTOFILL_HINT_NAME, AUTOFILL_HINT_PHONE, AUTOFILL_HINT_POSTAL_ADDRESS, AUTOFILL_HINT_POSTAL_CODE, AUTOFILL_HINT_CREDIT_CARD_NUMBER, AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE, AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE, AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY, AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH or AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR.
This method is only supported on API >= 26. On API 25 and below, it is a no-op
| Parameters | |
|---|---|
@NonNull View view |
view for which to set the hints. |
@Nullable String[] autofillHints |
The autofill hints to set. If the array is emtpy, |
setAutofillId
public static void setAutofillId(@NonNull View v, @Nullable AutofillIdCompat id)
Sets the unique, logical identifier of this view in the activity, for autofill purposes.
The autofill id is created on demand, and this method should only be called when a view is reused after dispatchProvideAutofillStructure is called, as that method creates a snapshot of the view that is passed along to the autofill service.
This method is typically used when view subtrees are recycled to represent different content* —in this case, the autofill id can be saved before the view content is swapped out, and restored later when it's swapped back in. For example:
EditText reusableView = ...;
ViewGroup parentView = ...;
AutofillManager afm = ...;
// Swap out the view and change its contents
AutofillId oldId = reusableView.getAutofillId();
CharSequence oldText = reusableView.getText();
parentView.removeView(reusableView);
AutofillId newId = afm.getNextAutofillId();
reusableView.setText("New I am");
reusableView.setAutofillId(newId);
parentView.addView(reusableView);
// Later, swap the old content back in
parentView.removeView(reusableView);
reusableView.setAutofillId(oldId);
reusableView.setText(oldText);
parentView.addView(reusableView);NOTE: If this view is a descendant of an android.widget.AdapterView, the system may reset its autofill id when this view is recycled. If the autofill ids need to be stable, they should be set again in getView. Compatibility behavior:
- SDK 28 and above, this method matches platform behavior.
- SDK 27 and below, this method does nothing.
| Parameters | |
|---|---|
@NonNull View v |
The View against which to invoke the method. |
@Nullable AutofillIdCompat id |
an autofill ID that is unique in the |
| Throws | |
|---|---|
java.lang.IllegalStateException |
if the view is already attached to a window. |
java.lang.IllegalArgumentException |
if the id is an autofill id associated with a virtual view. |
@ReplaceWith(expression = "view.setBackground(background)")
public static voidsetBackground(@NonNull View view, @Nullable Drawable background)
Set the background of the view to a given Drawable, or remove the background. If the background has padding, 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).
setBackgroundTintList
public static void setBackgroundTintList(
@NonNull View view,
@Nullable ColorStateList tintList
)
Applies a tint to the background drawable.
This will always take effect when running on API v21 or newer. When running on platforms previous to API v21, it will only take effect if view implements the TintableBackgroundView interface.
setBackgroundTintMode
public static void setBackgroundTintMode(@NonNull View view, @Nullable PorterDuff.Mode mode)
Specifies the blending mode used to apply the tint specified by setBackgroundTintList to the background drawable. The default mode is SRC_IN.
This will always take effect when running on API v21 or newer. When running on platforms previous to API v21, it will only take effect if view implement the TintableBackgroundView interface.
public static voidsetChildrenDrawingOrderEnabled(ViewGroup viewGroup, boolean enabled)
Tells the ViewGroup whether to draw its children in the order defined by the method ViewGroup.getChildDrawingOrder(int, int).
| Parameters | |
|---|---|
ViewGroup viewGroup |
the ViewGroup for which to set the mode. |
boolean enabled |
true if the order of the children when drawing is determined by Prior to API 7 this will have no effect. |
@ReplaceWith(expression = "view.setClipBounds(clipBounds)")
public static voidsetClipBounds(@NonNull View view, @Nullable 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.
Prior to API 18 this does nothing.
setContentCaptureSession
public static void setContentCaptureSession(
@NonNull View v,
@Nullable ContentCaptureSessionCompat contentCaptureSession
)
Sets the (optional) ContentCaptureSession associated with this view.
This method should be called when you need to associate a ContentCaptureContext to the content capture events associated with this view or its view hierarchy (if it's a ViewGroup).
For example, if your activity is associated with a web domain, first you would need to set the context for the main DOM:
ContentCaptureSession mainSession = rootView.getContentCaptureSession(); mainSession.setContentCaptureContext(ContentCaptureContext.forLocusId(Uri.parse(myUrl));
Then if the page had an IFRAME, you would create a new session for it:
ContentCaptureSession iframeSession = mainSession.createContentCaptureSession(
ContentCaptureContext.forLocusId(Uri.parse(iframeUrl)));
iframeView.setContentCaptureSession(iframeSession);- SDK 29 and above, this method matches platform behavior.
- SDK 28 and below, this method does nothing.
| Parameters | |
|---|---|
@NonNull View v |
The View against which to invoke the method. |
@Nullable ContentCaptureSessionCompat contentCaptureSession |
a session created by |
@ReplaceWith(expression = "view.setFitsSystemWindows(fitSystemWindows)")
public static voidsetFitsSystemWindows(View view, 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 will be executed. See that method for more details.
| Parameters | |
|---|---|
View view |
view for which to set the state. |
boolean fitSystemWindows |
whether or not this view should account for system screen decorations. |
setFocusedByDefault
public static void setFocusedByDefault(@NonNull View view, boolean isFocusedByDefault)
Sets whether view should receive focus when the focus is restored for the view hierarchy containing it.
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.
Does nothing on API <26.
@ReplaceWith(expression = "view.setHasTransientState(hasTransientState)")
public static voidsetHasTransientState(@NonNull View view, boolean hasTransientState)
Set whether this view is currently tracking transient state that the framework should attempt to preserve when possible.
@ReplaceWith(expression = "view.setImportantForAccessibility(mode)")
@UiThread
public static voidsetImportantForAccessibility(@NonNull 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.
Note: If the current platform version does not support the IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS mode, then IMPORTANT_FOR_ACCESSIBILITY_NO will be used as it is the closest terms of semantics.
setImportantForAutofill
public static void setImportantForAutofill(@NonNull View v, int mode)
Sets the mode for determining whether this view is considered important for autofill.
The platform determines the importance for autofill automatically but you can use this method to customize the behavior. For example:
- When the view contents is irrelevant for autofill (for example, a text field used in a "Captcha" challenge), it should be
IMPORTANT_FOR_AUTOFILL_NO. - When both the view and its children are irrelevant for autofill (for example, the root view of an activity containing a spreadhseet editor), it should be
IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS. - When the view content is relevant for autofill but its children aren't (for example, a credit card expiration date represented by a custom view that overrides the proper autofill methods and has 2 children representing the month and year), it should be
IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS.
NOTE: setting the mode as does IMPORTANT_FOR_AUTOFILL_NO or IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS does not guarantee the view (and its children) will be always be considered not important; for example, when the user explicitly makes an autofill request, all views are considered important. See isImportantForAutofill for more details about how the View's importance for autofill is used.
This method is only supported on API >= 26. On API 25 and below, it is a no-op
| Parameters | |
|---|---|
@NonNull View v |
The View against which to invoke the method. |
int mode |
|
setImportantForContentCapture
public static void setImportantForContentCapture(@NonNull View v, int mode)
Sets the mode for determining whether this view is considered important for content capture.
The platform determines the importance for autofill automatically but you can use this method to customize the behavior. Typically, a view that provides text should be marked as IMPORTANT_FOR_CONTENT_CAPTURE_YES. Compatibility behavior:
- SDK 30 and above, this method matches platform behavior.
- SDK 29 and below, this method does nothing.
ref android.R.styleable#View_importantForContentCapture
| Parameters | |
|---|---|
@NonNull View v |
The View against which to invoke the method. |
int mode |
|
setKeyboardNavigationCluster
public static void setKeyboardNavigationCluster(@NonNull View view, boolean isCluster)
Set whether view is a root of a keyboard navigation cluster. Does nothing if API <26.
@ReplaceWith(expression = "view.setLabelFor(labeledId)")
public static voidsetLabelFor(@NonNull View view, @IdRes int labeledId)
Sets the id of a view for which a given view serves as a label for accessibility purposes.
@ReplaceWith(expression = "view.setLayerPaint(paint)")
public static voidsetLayerPaint(@NonNull View view, @Nullable 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 will be used the next time the View is redrawn, but setLayerPaint must be called to ensure that the view gets redrawn immediately.
A layer is associated with an optional android.graphics.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 View#setAlpha(float), the alpha value of the layer's paint is replaced by this view's alpha value. Calling View#setAlpha(float) is therefore equivalent to setting a hardware layer on this view and providing a paint with the desired alpha value.
| Parameters | |
|---|---|
@NonNull View view |
View to set a layer paint for |
@Nullable 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 |
| See also | |
|---|---|
setLayerType |
@ReplaceWith(expression = "view.setLayerType(layerType, paint)")
public static voidsetLayerType(View view, int layerType, Paint paint)
Specifies the type of layer backing this view. The layer can be disabled, software or hardware.
A layer is associated with an optional android.graphics.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 replaced by this view's alpha value. Calling setAlpha(float) is therefore equivalent to setting a hardware layer on this view and providing a paint with the desired alpha value.
Refer to the documentation of disabled, software and hardware for more information on when and how to use layers.
| Parameters | |
|---|---|
View view |
View to set the layer type for |
int layerType |
The type of layer to use with this view, must be one of |
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 |
@ReplaceWith(expression = "view.setLayoutDirection(layoutDirection)")
public static voidsetLayoutDirection(@NonNull View view, 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.
| Parameters | |
|---|---|
@NonNull View view |
View to set layout direction for |
int layoutDirection |
the layout direction to set. Should be one of: |
setNestedScrollingEnabled
public static void setNestedScrollingEnabled(@NonNull View view, 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 | |
|---|---|
@NonNull View view |
view for which to set the state. |
boolean enabled |
true to enable nested scrolling, false to disable |
| See also | |
|---|---|
isNestedScrollingEnabled |
setNextClusterForwardId
public static void setNextClusterForwardId(@NonNull View view, int nextClusterForwardId)
Sets the ID of the next keyboard navigation cluster root view. Does nothing if view is not a keyboard navigation cluster or if API <26.
setOnApplyWindowInsetsListener
public static void setOnApplyWindowInsetsListener(
@NonNull View view,
@Nullable OnApplyWindowInsetsListener listener
)
Set an OnApplyWindowInsetsListener to take over the policy for applying window insets to this view. This will only take effect on devices with API 21 or above.
| Parameters | |
|---|---|
@NonNull View view |
view on which to the listener. |
@Nullable OnApplyWindowInsetsListener listener |
listener for the applied window insets. |
setOnReceiveContentListener
public static void setOnReceiveContentListener(
@NonNull View view,
@Nullable String[] mimeTypes,
@Nullable OnReceiveContentListener listener
)
Sets the listener to be used to handle insertion of content into the given view.
Depending on the type of view, this listener may be invoked for different scenarios. For example, for an AppCompatEditText, this listener will be invoked for the following scenarios:
- Paste from the clipboard (e.g. "Paste" or "Paste as plain text" action in the insertion/selection menu)
- Content insertion from the keyboard (from
commitContent) - Drag and drop (drop events from
onDragEvent)
When setting a listener, clients must also declare the accepted MIME types. The listener will still be invoked even if the MIME type of the content is not one of the declared MIME types (e.g. if the user pastes content whose type is not one of the declared MIME types). In that case, the listener may reject the content (defer to the default platform behavior) or execute some other fallback logic (e.g. show an appropriate message to the user). The declared MIME types serve as a hint to allow different features to optionally alter their behavior. For example, a soft keyboard may optionally choose to hide its UI for inserting GIFs for a particular input field if the MIME types set here for that field don't include "image/gif" or "image/*".
Note: 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 normalizeMimeType to ensure that it is converted to lowercase.
| Parameters | |
|---|---|
@NonNull View view |
The target view. |
@Nullable String[] mimeTypes |
The MIME types accepted by the given listener. These may use patterns such as "image/*", but may not start with a wildcard. This argument must not be null or empty if a non-null listener is passed in. |
@Nullable OnReceiveContentListener listener |
The listener to use. This can be null to reset to the default behavior. |
@ReplaceWith(expression = "view.setOverScrollMode(overScrollMode)")
public static voidsetOverScrollMode(View view, 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 | |
|---|---|
View view |
The View against which to invoke the method. |
int overScrollMode |
The new over-scroll mode for this view. |
@ReplaceWith(expression = "view.setPaddingRelative(start, top, end, bottom)")
public static voidsetPaddingRelative(
@NonNull View view,
@Px int start,
@Px int top,
@Px int end,
@Px 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.
@ReplaceWith(expression = "view.setPivotX(value)")
public static voidsetPivotX(View view, float value)
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.
| Parameters | |
|---|---|
View view |
view for which to set the pivot. |
float value |
The x location of the pivot point. |
@ReplaceWith(expression = "view.setPivotY(value)")
public static voidsetPivotY(View view, float value)
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.
| Parameters | |
|---|---|
View view |
view for which to set the pivot. |
float value |
The y location of the pivot point. |
setPointerIcon
public static void setPointerIcon(@NonNull View view, @Nullable PointerIconCompat pointerIcon)
Set the pointer icon for the current view.
| Parameters | |
|---|---|
@NonNull View view |
view for which to set the pointer icon. |
@Nullable PointerIconCompat pointerIcon |
A PointerIconCompat instance which will be shown when the mouse hovers. |
@ReplaceWith(expression = "view.setRotation(value)")
public static voidsetRotation(View view, float value)
Sets the degrees that the view is rotated around the pivot point. Increasing values result in clockwise rotation.
| Parameters | |
|---|---|
View view |
view to set the rotation on. |
float value |
The degrees of rotation. |
@ReplaceWith(expression = "view.setRotationX(value)")
public static voidsetRotationX(View view, float value)
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.
| Parameters | |
|---|---|
View view |
view to set the rotation on. |
float value |
The degrees of X rotation. |
@ReplaceWith(expression = "view.setRotationY(value)")
public static voidsetRotationY(View view, float value)
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.
| Parameters | |
|---|---|
View view |
view to set the rotation on. |
float value |
The degrees of Y rotation. |
@ReplaceWith(expression = "view.setSaveFromParentEnabled(enabled)")
public static voidsetSaveFromParentEnabled(View view, boolean enabled)
Controls whether the entire hierarchy under this view will save its state when a state saving traversal occurs from its parent.
| Parameters | |
|---|---|
View view |
view for which to set the state. |
boolean enabled |
Set to false to disable state saving, or true (the default) to allow it. |
@ReplaceWith(expression = "view.setScaleX(value)")
public static voidsetScaleX(View view, float value)
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.
| Parameters | |
|---|---|
View view |
view to set the scale on. |
float value |
The scaling factor. |
@ReplaceWith(expression = "view.setScaleY(value)")
public static voidsetScaleY(View view, float value)
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.
| Parameters | |
|---|---|
View view |
view to set the scale on. |
float value |
The scaling factor. |
setScreenReaderFocusable
@UiThread
public static void setScreenReaderFocusable(
@NonNull 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.
Note: this is similar to using android:focusable, but does not impact input focus behavior.
setScrollIndicators
public static void setScrollIndicators(@NonNull View view, int indicators)
Sets the state of all scroll indicators.
See setScrollIndicators for usage information.
| Parameters | |
|---|---|
@NonNull View view |
view for which to set the state. |
int indicators |
a bitmask of indicators that should be enabled, or |
| See also | |
|---|---|
setScrollIndicators |
|
getScrollIndicators |
setScrollIndicators
public static void setScrollIndicators(@NonNull View view, int indicators, int mask)
Sets the state of the scroll indicators specified by the mask. To change all scroll indicators at once, see setScrollIndicators.
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: setScrollIndicators
| Parameters | |
|---|---|
@NonNull View view |
view for which to set the state. |
int indicators |
the indicator direction, or the logical OR of multiple indicator directions. One or more of: |
int mask |
the mask for scroll indicators. |
| See also | |
|---|---|
setScrollIndicators |
|
getScrollIndicators |
setStateDescription
@UiThread
public static void setStateDescription(
@NonNull View view,
@Nullable CharSequence stateDescription
)
Sets the state description of this node.
Note: Cannot be called from an android.accessibilityservice.AccessibilityService. This class is made immutable before being delivered to an AccessibilityService.
State refers to a frequently changing property of the View, such as an enabled/disabled state of a button or the audio level of a volume slider.
This should omit role or content. Role refers to the kind of user-interface element the View is, such as a Button or Checkbox. Content is the meaningful text and graphics that should be described by setContentDescription or android:contentDescription. It is expected that a content description mostly remains constant, while a state description updates from time to time.
| Parameters | |
|---|---|
@NonNull View view |
view for which to set the description. |
@Nullable CharSequence stateDescription |
the state description of this node. |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If called from an AccessibilityService. |
| See also | |
|---|---|
setStateDescription |
|
setContentDescription |
setSystemGestureExclusionRects
public static void setSystemGestureExclusionRects(
@NonNull View view,
@NonNull 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. This method should be called by onLayout or onDraw.
On devices running API 28 and below, this method has no effect.
| Parameters | |
|---|---|
@NonNull View view |
view for which to set the exclusion rects. |
@NonNull List<Rect> rects |
A list of precision gesture regions that this view needs to function correctly |
| See also | |
|---|---|
setSystemGestureExclusionRects |
setTooltipText
public static void setTooltipText(@NonNull View view, @Nullable CharSequence tooltipText)
Sets the tooltip for the view.
Prior to API 26 this does nothing. Use TooltipCompat class from v7 appcompat library for a compatible tooltip implementation.
| Parameters | |
|---|---|
@NonNull View view |
view for which to set the tooltip. |
@Nullable CharSequence tooltipText |
the tooltip text |
setTransitionName
public static void setTransitionName(@NonNull View view, @Nullable String transitionName)
Sets the name of the View to be used to identify Views in Transitions. Names should be unique in the View hierarchy.
@ReplaceWith(expression = "view.setTranslationX(value)")
public static voidsetTranslationX(View view, float value)
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.
| Parameters | |
|---|---|
View view |
view for which to set the translation. |
float value |
The horizontal position of this view relative to its left position, in pixels. |
@ReplaceWith(expression = "view.setTranslationY(value)")
public static voidsetTranslationY(View view, float value)
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.
name android:translationY
| Parameters | |
|---|---|
View view |
view for which to set the translation. |
float value |
The vertical position of this view relative to its top position, in pixels. |
setTranslationZ
public static void setTranslationZ(@NonNull View view, float translationZ)
Sets the depth location of this view relative to its elevation.
setWindowInsetsAnimationCallback
public static void setWindowInsetsAnimationCallback(
@NonNull View view,
@Nullable WindowInsetsAnimationCompat.Callback callback
)
Sets a WindowInsetsAnimationCompat.Callback to be notified about animations of windows that cause insets.
The callback's dispatch mode will affect whether animation callbacks are dispatched to the children of this view.
Prior to API 30, if an OnApplyWindowInsetsListener is used on the same view, be sure to always use the ViewCompat version of setOnApplyWindowInsetsListener, otherwise the listener will be overridden by this method.
The insets dispatch needs to reach this view for the listener to be called. If any view consumed the insets earlier in the dispatch, this won't be called.
Prior to API 21, this method has no effect.
| Parameters | |
|---|---|
@NonNull View view |
view for which to set the callback. |
@Nullable WindowInsetsAnimationCompat.Callback callback |
The callback to set, or |
@ReplaceWith(expression = "view.setX(value)")
public static voidsetX(View view, float value)
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 of the view as determined by the layout bounds.
| Parameters | |
|---|---|
View view |
view to set the position on. |
float value |
The visual x position of this view, in pixels. |
@ReplaceWith(expression = "view.setY(value)")
public static voidsetY(View view, float value)
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 of the view as determined by the layout bounds.
| Parameters | |
|---|---|
View view |
view to set the position on. |
float value |
The visual y position of this view, in pixels. |
setZ
public static void setZ(@NonNull View view, 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.
Compatibility:
- API <21: No-op
startDragAndDrop
public static boolean startDragAndDrop(
@NonNull View v,
@Nullable ClipData data,
@NonNull View.DragShadowBuilder shadowBuilder,
@Nullable Object myLocalState,
int flags
)
Start the drag and drop operation.
startNestedScroll
public static boolean startNestedScroll(@NonNull View view, int axes)
Begin a nestable scroll operation along the given axes.
This version of the method just calls startNestedScroll using the touch input type.
| Parameters | |
|---|---|
@NonNull View view |
view for which to start the scroll. |
int axes |
Flags consisting of a combination of |
| Returns | |
|---|---|
boolean |
true if a cooperative parent was found and nested scrolling has been enabled for the current gesture. |
startNestedScroll
public static boolean startNestedScroll(@NonNull View view, int axes, int type)
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. 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.
| Parameters | |
|---|---|
@NonNull View view |
view on which to start the scroll. |
int axes |
Flags consisting of a combination of |
int type |
the type of input which cause this scroll event |
| Returns | |
|---|---|
boolean |
true if a cooperative parent was found and nested scrolling has been enabled for the current gesture. |
stopNestedScroll
public static void stopNestedScroll(@NonNull View view)
Stop a nested scroll in progress.
This version of the method just calls stopNestedScroll using the touch input type.
| See also | |
|---|---|
startNestedScroll |
stopNestedScroll
public static void stopNestedScroll(@NonNull View view, int type)
Stop a nested scroll in progress.
Calling this method when a nested scroll is not currently in progress is harmless.
| Parameters | |
|---|---|
@NonNull View view |
view for which to stop the scroll. |
int type |
the type of input which cause this scroll event |
| See also | |
|---|---|
startNestedScroll |
transformMatrixToGlobal
public static void transformMatrixToGlobal(@NonNull View view, @NonNull Matrix matrix)
Modifies the input matrix such that it maps on-screen coordinates to view-local coordinates for the provided view.
updateDragShadow
public static void updateDragShadow(
@NonNull View v,
@NonNull View.DragShadowBuilder shadowBuilder
)
Update the drag shadow while drag and drop is in progress.