-
public class ViewCompat
Helper for accessing features in View.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public @interface
ViewCompat.FocusDirection
public @interface
ViewCompat.FocusRealDirection
public @interface
ViewCompat.FocusRelativeDirection
public @interface
ViewCompat.ScrollAxis
public @interface
ViewCompat.NestedScrollType
public @interface
ViewCompat.ScrollIndicators
public interface
ViewCompat.OnUnhandledKeyEventListenerCompat
Interface definition for a callback to be invoked when a hardware key event hasn'tbeen handled by the view hierarchy.
-
Field Summary
Fields Modifier and Type Field Description public final static int
OVER_SCROLL_ALWAYS
public final static int
OVER_SCROLL_IF_CONTENT_SCROLLS
public final static int
OVER_SCROLL_NEVER
public final static int
LAYER_TYPE_NONE
public final static int
LAYER_TYPE_SOFTWARE
public final static int
LAYER_TYPE_HARDWARE
public final static int
LAYOUT_DIRECTION_LTR
public final static int
LAYOUT_DIRECTION_RTL
public final static int
LAYOUT_DIRECTION_INHERIT
public final static int
LAYOUT_DIRECTION_LOCALE
public final static int
MEASURED_SIZE_MASK
public final static int
MEASURED_STATE_MASK
public final static int
MEASURED_HEIGHT_STATE_SHIFT
public final static int
MEASURED_STATE_TOO_SMALL
public final static int
SCROLL_AXIS_NONE
public final static int
SCROLL_AXIS_HORIZONTAL
public final static int
SCROLL_AXIS_VERTICAL
public final static int
TYPE_TOUCH
public final static int
TYPE_NON_TOUCH
public final static int
SCROLL_INDICATOR_TOP
public final static int
SCROLL_INDICATOR_BOTTOM
public final static int
SCROLL_INDICATOR_LEFT
public final static int
SCROLL_INDICATOR_RIGHT
public final static int
SCROLL_INDICATOR_START
public final static int
SCROLL_INDICATOR_END
-
Method Summary
Modifier and Type Method Description static void
saveAttributeDataForStyleable(@NonNull() View view, @NonNull() Context context, @NonNull() Array<int> styleable, @Nullable() AttributeSet attrs, @NonNull() TypedArray t, int defStyleAttr, int defStyleRes)
Stores debugging information about attributes. static boolean
canScrollHorizontally(View view, int direction)
Check if this view can be scrolled horizontally in a certain direction. static boolean
canScrollVertically(View view, int direction)
Check if this view can be scrolled vertically in a certain direction. static int
getOverScrollMode(View v)
Returns the over-scroll mode for this view. static void
setOverScrollMode(View v, int overScrollMode)
Set the over-scroll mode for this view. static void
setAutofillHints(@NonNull() View v, @Nullable() Array<String> autofillHints)
Sets the hints that help an android.service.autofill.AutofillService determine howto autofill the view with the user's data. static int
getImportantForAutofill(@NonNull() View v)
Gets the mode for determining whether this view is important for autofill. static void
setImportantForAutofill(@NonNull() View v, int mode)
Sets the mode for determining whether this view is considered important for autofill. 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. static boolean
hasTransientState(@NonNull() View view)
Indicates whether the view is currently tracking transient state that theapp should not need to concern itself with saving and restoring, but thatthe framework should take special note to preserve when possible. static void
setHasTransientState(@NonNull() View view, boolean hasTransientState)
Set whether this view is currently tracking transient state that theframework should attempt to preserve when possible. static void
postInvalidateOnAnimation(@NonNull() View view)
Cause an invalidate to happen on the next animation time step, typically thenext display frame. static void
postInvalidateOnAnimation(@NonNull() View view, int left, int top, int right, int bottom)
Cause an invalidate of the specified area to happen on the next animationtime step, typically the next display frame. static void
postOnAnimation(@NonNull() View view, Runnable action)
Causes the Runnable to execute on the next animation time step.The runnable will be run on the user interface thread. static void
postOnAnimationDelayed(@NonNull() View view, 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. static float
getAlpha(View view)
The opacity of the view. static void
setLayerType(View view, int layerType, Paint paint)
Specifies the type of layer backing this view. static int
getLayerType(View view)
Indicates what type of layer is currently associated with this view. static void
setLayerPaint(@NonNull() View view, Paint paint)
Updates the Paint object used with the current layer (used only if the currentlayer type is not set to LAYER_TYPE_NONE). static int
getLayoutDirection(@NonNull() View view)
Returns the resolved layout direction for this view. static void
setLayoutDirection(@NonNull() View view, int layoutDirection)
Set the layout direction for this view. static <T extends View> T
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 thereis no matching view in the hierarchy. static boolean
isOpaque(View view)
Indicates whether this View is opaque. static int
resolveSizeAndState(int size, int measureSpec, int childMeasuredState)
Utility to reconcile a desired size and state, with constraints imposedby a MeasureSpec. static int
getMeasuredWidthAndState(View view)
Return the full width measurement information for this view as computedby the most recent call to measure. static int
getMeasuredHeightAndState(View view)
Return the full height measurement information for this view as computedby the most recent call to measure. static int
getMeasuredState(View view)
Return only the state bits of getMeasuredWidthAndState and getMeasuredHeightAndState, combined into one integer. static int
combineMeasuredStates(int curState, int newState)
Merge two states as returned by getMeasuredState. static int
getPaddingStart(@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 spacerequired to display the scrollbars as well. static int
getPaddingEnd(@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 spacerequired to display the scrollbars as well. static void
setPaddingRelative(@NonNull() View view, @Px() int start, @Px() int top, @Px() int end, @Px() int bottom)
Sets the relative padding. static void
dispatchStartTemporaryDetach(@NonNull() View view)
Notify a view that it is being temporarily detached. static void
dispatchFinishTemporaryDetach(@NonNull() View view)
Notify a view that its temporary detach has ended; the view is now reattached. static float
getTranslationX(View view)
The horizontal location of this view relative to its left position.This position is post-layout, in addition to wherever the object'slayout placed it. static float
getTranslationY(View view)
The vertical location of this view relative to its top position.This position is post-layout, in addition to wherever the object'slayout placed it. static Matrix
getMatrix(View view)
The transform matrix of this view, which is calculated based on the currentrotation, scale, and pivot properties. static int
getMinimumWidth(@NonNull() View view)
Returns the minimum width of the view. static int
getMinimumHeight(@NonNull() View view)
Returns the minimum height of the view. static ViewPropertyAnimatorCompat
animate(@NonNull() View view)
This method returns a ViewPropertyAnimator object, which can be used to animatespecific properties on this View. static void
setTranslationX(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'slayout placed it. static void
setTranslationY(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'slayout placed it. static void
setAlpha(View view, @FloatRange(from = 0.0, to = 1.0) float value)
Sets the opacity of the view. static void
setX(View view, float value)
Sets the visual x position of this view, in pixels. static void
setY(View view, float value)
Sets the visual y position of this view, in pixels. static void
setRotation(View view, float value)
Sets the degrees that the view is rotated around the pivot point. static void
setRotationX(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 thex axis. static void
setRotationY(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 lookingdown the y axis. static void
setScaleX(View view, float value)
Sets the amount that the view is scaled in x around the pivot point, as a proportion ofthe view's unscaled width. static void
setScaleY(View view, float value)
Sets the amount that the view is scaled in Y around the pivot point, as a proportion ofthe view's unscaled width. static float
getPivotX(View view)
The x location of the point around which the view is rotated and scaled. static void
setPivotX(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 theexplicitly set pivotX and pivotY values. static float
getPivotY(View view)
The y location of the point around which the view is rotated and scaled. static void
setPivotY(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 theexplicitly set pivotX and pivotY values. static float
getRotation(View view)
static float
getRotationX(View view)
static float
getRotationY(View view)
static float
getScaleX(View view)
static float
getScaleY(View view)
static float
getX(View view)
static float
getY(View view)
static void
setElevation(@NonNull() View view, float elevation)
Sets the base elevation of this view, in pixels. static float
getElevation(@NonNull() View view)
The base elevation of this view relative to its parent, in pixels. static void
setTranslationZ(@NonNull() View view, float translationZ)
Sets the depth location of this view relative to its elevation. static float
getTranslationZ(@NonNull() View view)
The depth location of this view relative to its elevation. static void
setTransitionName(@NonNull() View view, String transitionName)
Sets the name of the View to be used to identify Views in Transitions.Names should be unique in the View hierarchy. static 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. static int
getWindowSystemUiVisibility(@NonNull() View view)
Returns the current system UI visibility that is currently set for the entire window. static void
requestApplyInsets(@NonNull() View view)
Ask that a new dispatch of {@code View.onApplyWindowInsets(WindowInsets)}
be performed.static void
setChildrenDrawingOrderEnabled(ViewGroup viewGroup, boolean enabled)
Tells the ViewGroup whether to draw its children in the order defined by the method {@code ViewGroup.getChildDrawingOrder(int, int)}
.static boolean
getFitsSystemWindows(@NonNull() View v)
Returns true if this view should adapt to fit system window insets. static void
setFitsSystemWindows(View view, boolean fitSystemWindows)
Sets whether or not this view should account for system screen decorationssuch as the status bar and inset its content; that is, controlling whetherthe default implementation of fitSystemWindows will beexecuted. static void
jumpDrawablesToCurrentState(View v)
On API 11 devices and above, call Drawable.jumpToCurrentState()
on all Drawable objects associated with this view.static void
setOnApplyWindowInsetsListener(@NonNull() View v, @Nullable() OnApplyWindowInsetsListener listener)
Set an OnApplyWindowInsetsListener to take over the policy for applyingwindow insets to this view. static WindowInsetsCompat
onApplyWindowInsets(@NonNull() View view, @NonNull() WindowInsetsCompat insets)
Called when the view should apply WindowInsetsCompat according to its internal policy. static WindowInsetsCompat
dispatchApplyWindowInsets(@NonNull() View view, @NonNull() WindowInsetsCompat insets)
Request to apply the given window insets to this view or another view in its subtree. 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 systemshould not intercept touch or other pointing device gestures. static List<Rect>
getSystemGestureExclusionRects(@NonNull() View view)
Retrieve the list of areas within this view's post-layout coordinate space where the systemshould not intercept touch or other pointing device gestures. static 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. static 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 propagateto those under it. static WindowInsetsControllerCompat
getWindowInsetsController(@NonNull() View view)
Retrieves a WindowInsetsControllerCompat of the window this view is attached to. static void
setSaveFromParentEnabled(View v, boolean enabled)
Controls whether the entire hierarchy under this view will save itsstate when a state saving traversal occurs from its parent. static void
setActivated(View view, boolean activated)
Changes the activated state of this view. static boolean
hasOverlappingRendering(@NonNull() View view)
Returns whether this View has content which overlaps. static boolean
isPaddingRelative(@NonNull() View view)
Return if the padding as been set through relative values {@code View.setPaddingRelative(int, int, int, int)}
or thrustatic void
setBackground(@NonNull() View view, @Nullable() Drawable background)
Set the background of the {@code view}
to a given Drawable, or remove the background.static ColorStateList
getBackgroundTintList(@NonNull() View view)
Return the tint applied to the background drawable, if specified. static void
setBackgroundTintList(@NonNull() View view, ColorStateList tintList)
Applies a tint to the background drawable. static PorterDuff.Mode
getBackgroundTintMode(@NonNull() View view)
Return the blending mode used to apply the tint to the backgrounddrawable, if specified. static void
setBackgroundTintMode(@NonNull() View view, PorterDuff.Mode mode)
Specifies the blending mode used to apply the tint specified by setBackgroundTintList tothe background drawable. static void
setNestedScrollingEnabled(@NonNull() View view, boolean enabled)
Enable or disable nested scrolling for this view. static boolean
isNestedScrollingEnabled(@NonNull() View view)
Returns true if nested scrolling is enabled for this view. static boolean
startNestedScroll(@NonNull() View view, int axes)
Begin a nestable scroll operation along the given axes. static void
stopNestedScroll(@NonNull() View view)
Stop a nested scroll in progress. static boolean
hasNestedScrollingParent(@NonNull() View view)
Returns true if this view has a nested scrolling parent. static boolean
dispatchNestedScroll(@NonNull() View view, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, @Nullable() Array<int> offsetInWindow)
Dispatch one step of a nested scroll in progress. static boolean
dispatchNestedPreScroll(@NonNull() View view, int dx, int dy, @Nullable() Array<int> consumed, @Nullable() Array<int> offsetInWindow)
Dispatch one step of a nested scroll in progress before this view consumes any portion of it. 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, int type)
Stop a nested scroll in progress. static boolean
hasNestedScrollingParent(@NonNull() View view, int type)
Returns true if this view has a nested scrolling parent. static void
dispatchNestedScroll(@NonNull() View view, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, @Nullable() Array<int> offsetInWindow, int type, @NonNull() Array<int> consumed)
Dispatch one step of a nested scroll in progress. static boolean
dispatchNestedScroll(@NonNull() View view, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, @Nullable() Array<int> offsetInWindow, int type)
Dispatch one step of a nested scroll in progress. static boolean
dispatchNestedPreScroll(@NonNull() View view, int dx, int dy, @Nullable() Array<int> consumed, @Nullable() Array<int> offsetInWindow, int type)
Dispatch one step of a nested scroll in progress before this view consumes any portion of it. static boolean
dispatchNestedFling(@NonNull() View view, float velocityX, float velocityY, boolean consumed)
Dispatch a fling to a nested scrolling parent. 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. static boolean
isInLayout(@NonNull() View view)
Returns whether the view hierarchy is currently undergoing a layout pass. static boolean
isLaidOut(@NonNull() View view)
Returns true if {@code view}
has been through at least one layout since itwas last attached to or detached from a window.static boolean
isLayoutDirectionResolved(@NonNull() View view)
Returns whether layout direction has been resolved. static float
getZ(@NonNull() View view)
The visual z position of this view, in pixels. static void
setZ(@NonNull() View view, float z)
Sets the visual z position of this view, in pixels. static void
offsetTopAndBottom(@NonNull() View view, int offset)
Offset this view's vertical location by the specified number of pixels. static void
offsetLeftAndRight(@NonNull() View view, int offset)
Offset this view's horizontal location by the specified amount of pixels. static void
setClipBounds(@NonNull() View view, Rect clipBounds)
Sets a rectangular area on this view to which the view will be clippedwhen it is drawn. static Rect
getClipBounds(@NonNull() View view)
Returns a copy of the current setClipBounds. static boolean
isAttachedToWindow(@NonNull() View view)
Returns true if the provided view is currently attached to a window. static boolean
hasOnClickListeners(@NonNull() View view)
Returns whether the provided view has an attached View.OnClickListener. 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 int
getScrollIndicators(@NonNull() View view)
Returns a bitmask representing the enabled scroll indicators. static void
setPointerIcon(@NonNull() View view, PointerIconCompat pointerIcon)
Set the pointer icon for the current view. static Display
getDisplay(@NonNull() View view)
Gets the logical display to which the view's window has been attached. static void
setTooltipText(@NonNull() View view, @Nullable() CharSequence tooltipText)
Sets the tooltip for the view. static boolean
startDragAndDrop(@NonNull() View v, ClipData data, View.DragShadowBuilder shadowBuilder, Object localState, int flags)
Start the drag and drop operation. static void
cancelDragAndDrop(@NonNull() View v)
Cancel the drag and drop operation. static void
updateDragShadow(@NonNull() View v, View.DragShadowBuilder shadowBuilder)
Update the drag shadow while drag and drop is in progress. static int
getNextClusterForwardId(@NonNull() View view)
Gets the ID of the next keyboard navigation cluster root. static void
setNextClusterForwardId(@NonNull() View view, int nextClusterForwardId)
Sets the ID of the next keyboard navigation cluster root view. static boolean
isKeyboardNavigationCluster(@NonNull() View view)
Returns whether {@code view}
is a root of a keyboard navigation cluster.static void
setKeyboardNavigationCluster(@NonNull() View view, boolean isCluster)
Set whether {@code view}
is a root of a keyboard navigation cluster.static boolean
isFocusedByDefault(@NonNull() View view)
Returns whether {@code view}
should receive focus when the focus is restored for the viewhierarchy containing it.static void
setFocusedByDefault(@NonNull() View view, boolean isFocusedByDefault)
Sets whether {@code view}
should receive focus when the focus is restored for the viewhierarchy containing it.static View
keyboardNavigationClusterSearch(@NonNull() View view, View currentCluster, int direction)
Find the nearest keyboard navigation cluster in the specified direction.This does not actually give focus to that cluster. static void
addKeyboardNavigationClusters(@NonNull() View view, @NonNull() Collection<View> views, int direction)
Adds any keyboard navigation cluster roots that are descendants of {@code view}
(including{@code view}
if it is a cluster root itself) to{@code views}
.static boolean
restoreDefaultFocus(@NonNull() View view)
Gives focus to the default-focus view in the view hierarchy rooted at {@code view}
.static boolean
hasExplicitFocusable(@NonNull() View view)
Returns true if this view is focusable or if it contains a reachable Viewfor which hasExplicitFocusable returns {@code true}
.A "reachable hasExplicitFocusable()" is a view whose parents do not block descendants focus.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. static void
addOnUnhandledKeyEventListener(@NonNull() View v, @NonNull() ViewCompat.OnUnhandledKeyEventListenerCompat listener)
Adds a listener which will receive unhandled KeyEvents. static void
removeOnUnhandledKeyEventListener(@NonNull() View v, @NonNull() ViewCompat.OnUnhandledKeyEventListenerCompat listener)
Removes a listener which will receive unhandled KeyEvents. -
-
Method Detail
-
saveAttributeDataForStyleable
static void saveAttributeDataForStyleable(@NonNull() View view, @NonNull() Context context, @NonNull() Array<int> styleable, @Nullable() AttributeSet attrs, @NonNull() TypedArray t, int defStyleAttr, int defStyleRes)
Stores debugging information about attributes. This should be called in a constructor byevery 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:
context
- Context under which this view is created.styleable
- A reference to styleable array R.styleable.attrs
- AttributeSet used to construct this view.t
- Resolved TypedArray returned by a call toobtainAttributes.defStyleAttr
- Default style attribute passed into the view constructor.defStyleRes
- Default style resource passed into the view constructor.
-
canScrollHorizontally
@Deprecated() static boolean canScrollHorizontally(View view, int direction)
Check if this view can be scrolled horizontally in a certain direction.
- Parameters:
view
- The View against which to invoke the method.direction
- Negative to check scrolling left, positive to check scrolling right.
-
canScrollVertically
@Deprecated() static boolean canScrollVertically(View view, int direction)
Check if this view can be scrolled vertically in a certain direction.
- Parameters:
view
- The View against which to invoke the method.direction
- Negative to check scrolling up, positive to check scrolling down.
-
getOverScrollMode
@Deprecated() static int getOverScrollMode(View v)
Returns the over-scroll mode for this view. The result will beone of OVER_SCROLL_ALWAYS (default), OVER_SCROLL_IF_CONTENT_SCROLLS (allow over-scrolling only if the view content is larger than the container),or OVER_SCROLL_NEVER.
- Parameters:
v
- The View against which to invoke the method.
-
setOverScrollMode
@Deprecated() static void setOverScrollMode(View v, 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 theview is capable of scrolling.
- Parameters:
v
- The View against which to invoke the method.overScrollMode
- The new over-scroll mode for this view.
-
setAutofillHints
static void setAutofillHints(@NonNull() View v, @Nullable() Array<String> autofillHints)
Sets the hints that help an android.service.autofill.AutofillService determine howto 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 identifyan 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
{@code 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:
autofillHints
- The autofill hints to set.
-
getImportantForAutofill
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.
-
setImportantForAutofill
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 youcan 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 rootview of an activity containing a spreadhseet editor), it should beIMPORTANT_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 properautofill methods and has 2 children representing the month and year), it shouldbe 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 (andits children) will be always be considered not important; for example, when the userexplicitly makes an autofill request, all views are considered important. See isImportantForAutofill for more details about how the View's importance forautofill is used.
This method is only supported on API >= 26.On API 25 and below, it is a no-op
-
isImportantForAutofill
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.AutofillService determine how other views can be autofilled.
For example, view containers should typically return
{@code false}
for performance reasons(since the important info is provided by their children), but if its properties have relevantinformation (for example, a resource id called{@code credentials}
, it should return{@code true}
. On the other hand, views representing labels or editable fields shouldtypically return{@code true}
, but in some cases they could return{@code false}
(for example, if they're part of a "Captcha" mechanism).The value returned by this method depends on the value returned by getImportantForAutofill:
When a view is considered important for autofill:
On the other hand, when a view is considered not important for autofill:
This method is only supported on API >= 26.On API 25 and below, it will always return
{@code true}
.
-
hasTransientState
static boolean hasTransientState(@NonNull() View view)
Indicates whether the view is currently tracking transient state that theapp should not need to concern itself with saving and restoring, but thatthe framework should take special note to preserve when possible.
- Parameters:
view
- View to check for transient state
-
setHasTransientState
static void setHasTransientState(@NonNull() View view, boolean hasTransientState)
Set whether this view is currently tracking transient state that theframework should attempt to preserve when possible.
- Parameters:
view
- View tracking transient statehasTransientState
- true if this view has transient state
-
postInvalidateOnAnimation
static void postInvalidateOnAnimation(@NonNull() View view)
Cause an invalidate to happen on the next animation time step, typically thenext display frame.
This method can be invoked from outside of the UI threadonly when this View is attached to a window.
- Parameters:
view
- View to invalidate
-
postInvalidateOnAnimation
static void postInvalidateOnAnimation(@NonNull() View view, int left, int top, int right, int bottom)
Cause an invalidate of the specified area to happen on the next animationtime step, typically the next display frame.
This method can be invoked from outside of the UI threadonly when this View is attached to a window.
- Parameters:
view
- View to invalidateleft
- The left coordinate of the rectangle to invalidate.top
- The top coordinate of the rectangle to invalidate.right
- The right coordinate of the rectangle to invalidate.bottom
- The bottom coordinate of the rectangle to invalidate.
-
postOnAnimation
static void postOnAnimation(@NonNull() View view, 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 threadonly when this View is attached to a window.
- Parameters:
view
- View to post this Runnable toaction
- The Runnable that will be executed.
-
postOnAnimationDelayed
static void postOnAnimationDelayed(@NonNull() View view, 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 threadonly when this View is attached to a window.
- Parameters:
view
- The view to post this Runnable toaction
- The Runnable that will be executed.delayMillis
- The delay (in milliseconds) until the Runnablewill be executed.
-
getAlpha
@Deprecated() static float getAlpha(View view)
The opacity of the view. This is a value from 0 to 1, where 0 means the view iscompletely transparent and 1 means the view is completely opaque.
By default this is 1.0f.
-
setLayerType
@Deprecated() static void setLayerType(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 Paint instance that controls how the layer is composed on screen. The followingproperties of the paint are taken into account when composing the layer:
If this view has an alpha value set to < 1.0 by callingsetAlpha(float), the alpha value of the layer's paint is replaced bythis view's alpha value. Calling setAlpha(float) is thereforeequivalent to setting a hardware layer on this view and providing a paint withthe 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 to set the layer type forlayerType
- The type of layer to use with this view, must be one ofLAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE orLAYER_TYPE_HARDWAREpaint
- The paint used to compose the layer.
-
getLayerType
@Deprecated() static int getLayerType(View view)
Indicates what type of layer is currently associated with this view. By defaulta 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
- The view to fetch the layer type from
-
setLayerPaint
static void setLayerPaint(@NonNull() View view, Paint paint)
Updates the Paint object used with the current layer (used only if the currentlayer type is not set to LAYER_TYPE_NONE). Changed properties of the Paintprovided 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 Paint instance that controls how the layer is composed on screen. The followingproperties of the paint are taken into account when composing the layer:
If this view has an alpha value set to < 1.0 by callingView#setAlpha(float), the alpha value of the layer's paint is replaced bythis view's alpha value. Calling View#setAlpha(float) is thereforeequivalent to setting a hardware layer on this view and providing a paint withthe desired alpha value.
- Parameters:
view
- View to set a layer paint forpaint
- The paint used to compose the layer.
-
getLayoutDirection
static int getLayoutDirection(@NonNull() View view)
Returns the resolved layout direction for this view.
- Parameters:
view
- View to get layout direction for
-
setLayoutDirection
static void setLayoutDirection(@NonNull() View view, int layoutDirection)
Set the layout direction for this view. This will propagate a reset of layout directionresolution to the view's children and resolve layout direction for this view.
- Parameters:
view
- View to set layout direction forlayoutDirection
- the layout direction to set.
-
requireViewById
@NonNull() static <T extends View> T 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 thereis 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. Ifthe target class type is unconstrained, an explicit cast may benecessary.
- Parameters:
id
- the ID to search for
-
isOpaque
@Deprecated() static boolean isOpaque(View view)
Indicates whether this View is opaque. An opaque View guarantees that it willdraw all the pixels overlapping its bounds using a fully opaque color.
-
resolveSizeAndState
@Deprecated() static int resolveSizeAndState(int size, int measureSpec, int childMeasuredState)
Utility to reconcile a desired size and state, with constraints imposedby a MeasureSpec. Will take the desired size, unless a different sizeis imposed by the constraints. The returned value is a compound integer,with the resolved size in the MEASURED_SIZE_MASK bits andoptionally the bit MEASURED_STATE_TOO_SMALL set if the resultingsize is smaller than the size the view wants to be.
- Parameters:
size
- How big the view wants to bemeasureSpec
- Constraints imposed by the parent
-
getMeasuredWidthAndState
@Deprecated() static int getMeasuredWidthAndState(View view)
Return the full width measurement information for this view as computedby 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.
-
getMeasuredHeightAndState
@Deprecated() static int getMeasuredHeightAndState(View view)
Return the full height measurement information for this view as computedby 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.
-
getMeasuredState
@Deprecated() static int getMeasuredState(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.
-
combineMeasuredStates
@Deprecated() static int combineMeasuredStates(int curState, int newState)
Merge two states as returned by getMeasuredState.
- Parameters:
curState
- The current state as returned from a view or the resultof combining multiple views.newState
- The new view state to combine.
-
getPaddingStart
@Px() static int getPaddingStart(@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 spacerequired to display the scrollbars as well.
- Parameters:
view
- The view to get padding for
-
getPaddingEnd
@Px() static int getPaddingEnd(@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 spacerequired to display the scrollbars as well.
- Parameters:
view
- The view to get padding for
-
setPaddingRelative
static void setPaddingRelative(@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 displaythe scrollbars, depending on the style and visibility of the scrollbars.So the values returned from getPaddingStart, getPaddingTop, getPaddingEnd and getPaddingBottom may be differentfrom the values set in this call.
- Parameters:
view
- The view on which to set relative paddingstart
- the start padding in pixelstop
- the top padding in pixelsend
- the end padding in pixelsbottom
- the bottom padding in pixels
-
dispatchStartTemporaryDetach
static void dispatchStartTemporaryDetach(@NonNull() View view)
Notify a view that it is being temporarily detached.
-
dispatchFinishTemporaryDetach
static void dispatchFinishTemporaryDetach(@NonNull() View view)
Notify a view that its temporary detach has ended; the view is now reattached.
-
getTranslationX
@Deprecated() static float getTranslationX(View view)
The horizontal location of this view relative to its left position.This position is post-layout, in addition to wherever the object'slayout placed it.
-
getTranslationY
@Deprecated() static float getTranslationY(View view)
The vertical location of this view relative to its top position.This position is post-layout, in addition to wherever the object'slayout placed it.
-
getMatrix
@Deprecated()@Nullable() static Matrix getMatrix(View view)
The transform matrix of this view, which is calculated based on the currentrotation, scale, and pivot properties.
- Parameters:
view
- The view whose Matrix will be returned
-
getMinimumWidth
static int getMinimumWidth(@NonNull() View view)
Returns the minimum width of the view.
Prior to API 16, this method may return 0 on some platforms.
-
getMinimumHeight
static int getMinimumHeight(@NonNull() View view)
Returns the minimum height of the view.
Prior to API 16, this method may return 0 on some platforms.
-
animate
@NonNull() static ViewPropertyAnimatorCompat animate(@NonNull() View view)
This method returns a ViewPropertyAnimator object, which can be used to animatespecific properties on this View.
-
setTranslationX
@Deprecated() static void setTranslationX(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'slayout placed it.
- Parameters:
value
- The horizontal position of this view relative to its left position,in pixels.
-
setTranslationY
@Deprecated() static void setTranslationY(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'slayout placed it.
- Parameters:
value
- The vertical position of this view relative to its top position,in pixels.
-
setAlpha
@Deprecated() static void setAlpha(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 iscompletely transparent and 1 means the view is completely opaque.
Note that setting alpha to a translucent value (0 < alpha < 1) can have significantperformance implications, especially for large views. It is best to use the alpha propertysparingly and transiently, as in the case of fading animations.
- Parameters:
value
- The opacity of the view.
-
setX
@Deprecated() static void setX(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 betweenthe x value passed in and the current left property of the view as determinedby the layout bounds.
- Parameters:
value
- The visual x position of this view, in pixels.
-
setY
@Deprecated() static void setY(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 betweenthe y value passed in and the current top property of the view as determined by thelayout bounds.
- Parameters:
value
- The visual y position of this view, in pixels.
-
setRotation
@Deprecated() static void setRotation(View view, float value)
Sets the degrees that the view is rotated around the pivot point. Increasing valuesresult in clockwise rotation.
- Parameters:
value
- The degrees of rotation.
-
setRotationX
@Deprecated() static void setRotationX(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 thex axis.
- Parameters:
value
- The degrees of X rotation.
-
setRotationY
@Deprecated() static void setRotationY(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 lookingdown the y axis.
- Parameters:
value
- The degrees of Y rotation.
-
setScaleX
@Deprecated() static void setScaleX(View view, float value)
Sets the amount that the view is scaled in x around the pivot point, as a proportion ofthe view's unscaled width. A value of 1 means that no scaling is applied.
- Parameters:
value
- The scaling factor.
-
setScaleY
@Deprecated() static void setScaleY(View view, float value)
Sets the amount that the view is scaled in Y around the pivot point, as a proportion ofthe view's unscaled width. A value of 1 means that no scaling is applied.
- Parameters:
value
- The scaling factor.
-
getPivotX
@Deprecated() static float getPivotX(View view)
-
setPivotX
@Deprecated() static void setPivotX(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 theexplicitly set pivotX and pivotY values.
- Parameters:
value
- The x location of the pivot point.
-
getPivotY
@Deprecated() static float getPivotY(View view)
-
setPivotY
@Deprecated() static void setPivotY(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 theexplicitly set pivotX and pivotY values.
- Parameters:
value
- The y location of the pivot point.
-
getRotation
@Deprecated() static float getRotation(View view)
-
getRotationX
@Deprecated() static float getRotationX(View view)
-
getRotationY
@Deprecated() static float getRotationY(View view)
-
getScaleX
@Deprecated() static float getScaleX(View view)
-
getScaleY
@Deprecated() static float getScaleY(View view)
-
getX
@Deprecated() static float getX(View view)
-
getY
@Deprecated() static float getY(View view)
-
setElevation
static void setElevation(@NonNull() View view, float elevation)
Sets the base elevation of this view, in pixels.
-
getElevation
static float getElevation(@NonNull() View view)
The base elevation of this view relative to its parent, in pixels.
-
setTranslationZ
static void setTranslationZ(@NonNull() View view, float translationZ)
Sets the depth location of this view relative to its elevation.
-
getTranslationZ
static float getTranslationZ(@NonNull() View view)
The depth location of this view relative to its elevation.
-
setTransitionName
static void setTransitionName(@NonNull() View view, String transitionName)
Sets the name of the View to be used to identify Views in Transitions.Names should be unique in the View hierarchy.
- Parameters:
view
- The View against which to invoke the method.transitionName
- The name of the View to uniquely identify it for Transitions.
-
getTransitionName
@Nullable() static 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.
- Parameters:
view
- The View against which to invoke the method.
-
getWindowSystemUiVisibility
static int getWindowSystemUiVisibility(@NonNull() View view)
Returns the current system UI visibility that is currently set for the entire window.
-
requestApplyInsets
static void requestApplyInsets(@NonNull() View view)
Ask that a new dispatch of
{@code View.onApplyWindowInsets(WindowInsets)}
be performed. Thisfalls back to{@code View.requestFitSystemWindows()}
where available.
-
setChildrenDrawingOrderEnabled
@Deprecated() static void setChildrenDrawingOrderEnabled(ViewGroup viewGroup, boolean enabled)
Tells the ViewGroup whether to draw its children in the order defined by the method
{@code ViewGroup.getChildDrawingOrder(int, int)}
.- Parameters:
enabled
- true if the order of the children when drawing is determined bygetChildDrawingOrder, false otherwisePrior to API 7 this will have no effect.
-
getFitsSystemWindows
static boolean getFitsSystemWindows(@NonNull() View v)
Returns true if this view should adapt to fit system window insets. This method will alwaysreturn false before API 16 (Jellybean).
-
setFitsSystemWindows
@Deprecated() static void setFitsSystemWindows(View view, boolean fitSystemWindows)
Sets whether or not this view should account for system screen decorationssuch as the status bar and inset its content; that is, controlling whetherthe default implementation of fitSystemWindows will beexecuted. See that method for more details.
-
jumpDrawablesToCurrentState
@Deprecated() static void jumpDrawablesToCurrentState(View v)
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.
-
setOnApplyWindowInsetsListener
static void setOnApplyWindowInsetsListener(@NonNull() View v, @Nullable() OnApplyWindowInsetsListener listener)
Set an OnApplyWindowInsetsListener to take over the policy for applyingwindow insets to this view. This will only take effect on devices with API 21 or above.
-
onApplyWindowInsets
@NonNull() static 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 setit will be called during dispatch instead of this method. The listener may optionallycall this method from its own implementation if it wishes to apply the view's defaultinsets policy in addition to its own.
- Parameters:
view
- The View against which to invoke the method.insets
- Insets to apply
-
dispatchApplyWindowInsets
@NonNull() static 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 areasobscured 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 itschildren.
- Parameters:
insets
- Insets to apply
-
setSystemGestureExclusionRects
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 systemshould not intercept touch or other pointing device gestures. This method shouldbe called by onLayout or onDraw.
On devices running API 28 and below, this method has no effect.
- Parameters:
rects
- A list of precision gesture regions that this view needs to function correctly
-
getSystemGestureExclusionRects
@NonNull() static List<Rect> getSystemGestureExclusionRects(@NonNull() View view)
Retrieve the list of areas within this view's post-layout coordinate space where the systemshould not intercept touch or other pointing device gestures.
On devices running API 28 and below, this method always returns an empty list.
-
getRootWindowInsets
@Nullable() static 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 22 and below, this method always returns null.
-
computeSystemWindowInsets
@NonNull() static 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 propagateto those under it.
- Parameters:
insets
- Insets currently being processed by this View, likely received as a parameterto onApplyWindowInsets.outLocalInsets
- A Rect that will receive the insets that should be consumedby this view
-
getWindowInsetsController
@Nullable() static WindowInsetsControllerCompat getWindowInsetsController(@NonNull() View view)
Retrieves a WindowInsetsControllerCompat of the window this view is attached to.
-
setSaveFromParentEnabled
@Deprecated() static void setSaveFromParentEnabled(View v, boolean enabled)
Controls whether the entire hierarchy under this view will save itsstate when a state saving traversal occurs from its parent.
- Parameters:
enabled
- Set to false to disable state saving, or true(the default) to allow it.
-
setActivated
@Deprecated() static void setActivated(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 isa transient property, representing the view (hierarchy) the user iscurrently interacting with. Activation is a longer-term state that theuser can move views in and out of.
- Parameters:
activated
- true if the view must be activated, false otherwise
-
hasOverlappingRendering
static boolean hasOverlappingRendering(@NonNull() View view)
Returns whether this View has content which overlaps.
This function, intended to be overridden by specific View types, is an optimization whenalpha is set on a view. If rendering overlaps in a view with alpha < 1, that view is drawn toan offscreen buffer and then composited into place, which can be expensive. If the view hasno overlapping rendering, the view can draw each primitive with the appropriate alpha valuedirectly. An example of overlapping rendering is a TextView with a background image, such asa Button. An example of non-overlapping rendering is a TextView with no background, or anImageView with only the foreground image. The default implementation returns true; subclassesshould override if they have cases which can be optimized.
-
isPaddingRelative
static boolean isPaddingRelative(@NonNull() View view)
Return if the padding as been set through relative values
{@code View.setPaddingRelative(int, int, int, int)}
or thru
-
setBackground
static void setBackground(@NonNull() View view, @Nullable() Drawable background)
Set the background of the
{@code view}
to a given Drawable, or remove the background. If thebackground has padding,{@code 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 isdesired, please use{@code setPadding(int, int, int, int)}
.
-
getBackgroundTintList
static 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
{@code view}
implements the{@code TintableBackgroundView}
interface.
-
setBackgroundTintList
static void setBackgroundTintList(@NonNull() View view, ColorStateList tintList)
Applies a tint to the background drawable.
This will always take effect when running on API v21 or newer. When running on platformsprevious to API v21, it will only take effect if
{@code view}
implements the{@code TintableBackgroundView}
interface.
-
getBackgroundTintMode
static PorterDuff.Mode getBackgroundTintMode(@NonNull() View view)
Return the blending mode used to apply the tint to the backgrounddrawable, if specified.
Only returns meaningful info when running on API v21 or newer, or if
{@code view}
implements the{@code TintableBackgroundView}
interface.
-
setBackgroundTintMode
static void setBackgroundTintMode(@NonNull() View view, PorterDuff.Mode mode)
Specifies the blending mode used to apply the tint specified by setBackgroundTintList tothe background drawable. The default mode is SRC_IN.
This will always take effect when running on API v21 or newer. When running on platformsprevious to API v21, it will only take effect if
{@code view}
implement the{@code TintableBackgroundView}
interface.
-
setNestedScrollingEnabled
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 nestedscrolling operations with a compatible parent view in the current hierarchy. If thisview does not implement nested scrolling this will have no effect. Disabling nested scrollingwhile a nested scroll is in progress has the effect of stopping the nested scroll.
- Parameters:
enabled
- true to enable nested scrolling, false to disable
-
isNestedScrollingEnabled
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 dataabout the scroll operation in progress to a compatible and cooperating nested scrollingparent.
-
startNestedScroll
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 usingthe touch input type.
- Parameters:
axes
- Flags consisting of a combination of SCROLL_AXIS_HORIZONTAL and/or SCROLL_AXIS_VERTICAL.
-
stopNestedScroll
static void stopNestedScroll(@NonNull() View view)
Stop a nested scroll in progress.
This version of the method just calls stopNestedScroll using thetouch input type.
-
hasNestedScrollingParent
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.
-
dispatchNestedScroll
static boolean dispatchNestedScroll(@NonNull() View view, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, @Nullable() Array<int> offsetInWindow)
Dispatch one step of a nested scroll in progress.
This version of the method just calls dispatchNestedScroll using the touch inputtype.
- Parameters:
dxConsumed
- Horizontal distance in pixels consumed by this view during this scroll stepdyConsumed
- Vertical distance in pixels consumed by this view during this scroll stepdxUnconsumed
- Horizontal scroll distance in pixels not consumed by this viewdyUnconsumed
- Horizontal scroll distance in pixels not consumed by this viewoffsetInWindow
- Optional.
-
dispatchNestedPreScroll
static boolean dispatchNestedPreScroll(@NonNull() View view, int dx, int dy, @Nullable() Array<int> consumed, @Nullable() Array<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 inputtype.
- Parameters:
dx
- Horizontal scroll distance in pixelsdy
- Vertical scroll distance in pixelsconsumed
- Output.offsetInWindow
- Optional.
-
startNestedScroll
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 caseof a touch scroll this corresponds to the initial ACTION_DOWN.In the case of touch scrolling the nested scroll will be terminated automatically inthe 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 scrollingparent at least partially consumed the scroll and the caller should adjust the amount itscrolls by.
After applying the remainder of the scroll delta the caller should invoke dispatchNestedScroll, passingboth the delta consumed and the delta unconsumed. A nested scrolling parent may treatthese values differently. See onNestedScroll.
- Parameters:
axes
- Flags consisting of a combination of SCROLL_AXIS_HORIZONTAL and/or SCROLL_AXIS_VERTICAL.type
- the type of input which cause this scroll event
-
stopNestedScroll
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:
type
- the type of input which cause this scroll event
-
hasNestedScrollingParent
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 initiateda nested scroll and it was accepted by an ancestor view further up the view hierarchy.
- Parameters:
type
- the type of input which cause this scroll event
-
dispatchNestedScroll
static void dispatchNestedScroll(@NonNull() View view, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, @Nullable() Array<int> offsetInWindow, int type, @NonNull() Array<int> consumed)
Dispatch one step of a nested scroll in progress.
Implementations of views that support nested scrolling should call this to reportinfo about a scroll in progress to the current nested scrolling parent. If a nested scrollis 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 nestedscrolling parents to report how much of the scroll distance was consumed. The originalcaller (where the input event was received to start the scroll) should initialize the valuesto be 0, in order to tell how much was actually consumed up the hierarchy of scrollingparents.- Parameters:
dxConsumed
- Horizontal distance in pixels consumed by this view during this scroll stepdyConsumed
- Vertical distance in pixels consumed by this view during this scroll stepdxUnconsumed
- Horizontal scroll distance in pixels not consumed by this viewdyUnconsumed
- Horizontal scroll distance in pixels not consumed by this viewoffsetInWindow
- Optional.type
- the type of input which cause this scroll eventconsumed
- Output, If not null,consumed[0]
will contain the consumedcomponent of dx andconsumed[1]
the consumed dy.
-
dispatchNestedScroll
static boolean dispatchNestedScroll(@NonNull() View view, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, @Nullable() Array<int> offsetInWindow, int type)
Dispatch one step of a nested scroll in progress.
Implementations of views that support nested scrolling should call this to reportinfo about a scroll in progress to the current nested scrolling parent. If a nested scrollis not currently in progress or nested scrolling is not enabled for this view this method does nothing.
Compatible View implementations should also call dispatchNestedPreScroll beforeconsuming a component of the scroll event themselves.
- Parameters:
dxConsumed
- Horizontal distance in pixels consumed by this view during this scroll stepdyConsumed
- Vertical distance in pixels consumed by this view during this scroll stepdxUnconsumed
- Horizontal scroll distance in pixels not consumed by this viewdyUnconsumed
- Horizontal scroll distance in pixels not consumed by this viewoffsetInWindow
- Optional.type
- the type of input which cause this scroll event
-
dispatchNestedPreScroll
static boolean dispatchNestedPreScroll(@NonNull() View view, int dx, int dy, @Nullable() Array<int> consumed, @Nullable() Array<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 nestedscrolling operation to consume some or all of the scroll operation before the child viewconsumes it.- Parameters:
dx
- Horizontal scroll distance in pixelsdy
- Vertical scroll distance in pixelsconsumed
- Output.offsetInWindow
- Optional.type
- the type of input which cause this scroll event
-
dispatchNestedFling
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 detectedsuitable conditions for a fling. Generally this means that a touch scroll has ended with a velocity in the direction of scrolling that meets or exceedsthe minimum fling velocity along a scrollable axis.
If a nested scrolling child view would normally fling but it is at the edge ofits own content, it can use this method to delegate the fling to its nested scrollingparent instead. The parent may optionally consume the fling or observe a child fling.
- Parameters:
velocityX
- Horizontal fling velocity in pixels per secondvelocityY
- Vertical fling velocity in pixels per secondconsumed
- true if the child consumed the fling, false otherwise
-
dispatchNestedPreFling
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 touchand what nested pre-scroll is to nested scroll.
dispatchNestedPreFling
offsets an opportunity for the parent view in a nested fling to fully consume the flingbefore the child view consumes it. If this method returnstrue
, a nestedparent 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 consumethe 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 notcall
dispatchNestedPreFling
; consume the fling and settle to a validposition 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 axiswhere scrolling is not currently supported; a ScrollView should not offer a horizontal fling velocity to its parents since scrolling along thataxis is not permitted and carrying velocity along that motion does not make sense.
- Parameters:
velocityX
- Horizontal fling velocity in pixels per secondvelocityY
- Vertical fling velocity in pixels per second
- If a custom view is paged and needs to settle to a fixed page-point, do notcall
-
isInLayout
static boolean isInLayout(@NonNull() View view)
Returns whether the view hierarchy is currently undergoing a layout pass. Thisinformation is useful to avoid situations such as calling requestLayout during a layout pass.
Compatibility:
- API < 18: Always returns
{@code false}
- API < 18: Always returns
-
isLaidOut
static boolean isLaidOut(@NonNull() View view)
Returns true if
{@code view}
has been through at least one layout since itwas last attached to or detached from a window.
-
isLayoutDirectionResolved
static boolean isLayoutDirectionResolved(@NonNull() View view)
Returns whether layout direction has been resolved.
Compatibility:
- API < 19: Always returns
{@code false}
- API < 19: Always returns
-
getZ
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.
-
setZ
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 betweenthe x value passed in and the current elevation property.
Compatibility:
- API < 21: No-op
- Parameters:
z
- The visual z position of this view, in pixels.
-
offsetTopAndBottom
static void offsetTopAndBottom(@NonNull() View view, int offset)
Offset this view's vertical location by the specified number of pixels.
- Parameters:
offset
- the number of pixels to offset the view by
-
offsetLeftAndRight
static void offsetLeftAndRight(@NonNull() View view, int offset)
Offset this view's horizontal location by the specified amount of pixels.
- Parameters:
offset
- the number of pixels to offset the view by
-
setClipBounds
static void setClipBounds(@NonNull() View view, Rect clipBounds)
Sets a rectangular area on this view to which the view will be clippedwhen it is drawn. Setting the value to null will remove the clip boundsand the view will draw normally, using its full bounds.
Prior to API 18 this does nothing.
- Parameters:
view
- The view to set clipBounds.clipBounds
- The rectangular area, in the local coordinates ofthis view, to which future drawing operations will be clipped.
-
getClipBounds
@Nullable() static Rect getClipBounds(@NonNull() View view)
Returns a copy of the current setClipBounds.
Prior to API 18 this will return null.
-
isAttachedToWindow
static boolean isAttachedToWindow(@NonNull() View view)
Returns true if the provided view is currently attached to a window.
-
hasOnClickListeners
static boolean hasOnClickListeners(@NonNull() View view)
Returns whether the provided view has an attached View.OnClickListener.
-
setScrollIndicators
static void setScrollIndicators(@NonNull() View view, int indicators)
Sets the state of all scroll indicators.
See setScrollIndicators for usage information.
- Parameters:
indicators
- a bitmask of indicators that should be enabled, or{@code 0}
to disable all indicators
-
setScrollIndicators
static void setScrollIndicators(@NonNull() View view, int indicators, int mask)
Sets the state of the scroll indicators specified by the mask. To changeall scroll indicators at once, see setScrollIndicators.
When a scroll indicator is enabled, it will be displayed if the viewcan scroll in the direction of the indicator.
Multiple indicator types may be enabled or disabled by passing thelogical OR of the desired types. If multiple types are specified, theywill all be set to the same enabled state.
For example, to enable the top scroll indicatorExample:
{@code setScrollIndicators}
- Parameters:
indicators
- the indicator direction, or the logical OR of multipleindicator directions.
-
getScrollIndicators
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 allother indicators are disabled, the return value will be
{@code ViewCompat.SCROLL_INDICATOR_TOP | ViewCompat.SCROLL_INDICATOR_LEFT}
.To check whether the bottom scroll indicator is enabled, use the valueof
{@code (ViewCompat.getScrollIndicators(view) & ViewCompat.SCROLL_INDICATOR_BOTTOM) != 0}
.
-
setPointerIcon
static void setPointerIcon(@NonNull() View view, PointerIconCompat pointerIcon)
Set the pointer icon for the current view.
- Parameters:
pointerIcon
- A PointerIconCompat instance which will be shown when the mouse hovers.
-
getDisplay
@Nullable() static Display getDisplay(@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.
-
setTooltipText
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 libraryfor a compatible tooltip implementation.
- Parameters:
tooltipText
- the tooltip text
-
startDragAndDrop
static boolean startDragAndDrop(@NonNull() View v, ClipData data, View.DragShadowBuilder shadowBuilder, Object localState, int flags)
Start the drag and drop operation.
-
cancelDragAndDrop
static void cancelDragAndDrop(@NonNull() View v)
Cancel the drag and drop operation.
-
updateDragShadow
static void updateDragShadow(@NonNull() View v, View.DragShadowBuilder shadowBuilder)
Update the drag shadow while drag and drop is in progress.
-
getNextClusterForwardId
static int getNextClusterForwardId(@NonNull() View view)
Gets the ID of the next keyboard navigation cluster root.
-
setNextClusterForwardId
static void setNextClusterForwardId(@NonNull() View view, int nextClusterForwardId)
Sets the ID of the next keyboard navigation cluster root view. Does nothing if
{@code view}
is not a keyboard navigation cluster or if API < 26.- Parameters:
nextClusterForwardId
- next cluster ID, or NO_ID if the frameworkshould decide automatically.
-
isKeyboardNavigationCluster
static boolean isKeyboardNavigationCluster(@NonNull() View view)
Returns whether
{@code view}
is a root of a keyboard navigation cluster. Always returns{@code false}
on API < 26.
-
setKeyboardNavigationCluster
static void setKeyboardNavigationCluster(@NonNull() View view, boolean isCluster)
Set whether
{@code view}
is a root of a keyboard navigation cluster. Does nothing ifAPI < 26.- Parameters:
isCluster
-{@code true}
to mark{@code view}
as the root of a cluster,{@code false}
to unmark.
-
isFocusedByDefault
static boolean isFocusedByDefault(@NonNull() View view)
Returns whether
{@code view}
should receive focus when the focus is restored for the viewhierarchy containing it. Returns{@code false}
on API < 26.Focus gets restored for a view hierarchy when the root of the hierarchy gets added to awindow or serves as a target of cluster navigation.
-
setFocusedByDefault
static void setFocusedByDefault(@NonNull() View view, boolean isFocusedByDefault)
Sets whether
{@code view}
should receive focus when the focus is restored for the viewhierarchy containing it.Focus gets restored for a view hierarchy when the root of the hierarchy gets added to awindow or serves as a target of cluster navigation.
Does nothing on API < 26.
- Parameters:
isFocusedByDefault
-{@code true}
to set{@code view}
as the default-focus view,{@code false}
otherwise.
-
keyboardNavigationClusterSearch
static View keyboardNavigationClusterSearch(@NonNull() View view, View currentCluster, int direction)
Find the nearest keyboard navigation cluster in the specified direction.This does not actually give focus to that cluster.
- Parameters:
currentCluster
- The starting point of the search.direction
- Direction to look.
-
addKeyboardNavigationClusters
static void addKeyboardNavigationClusters(@NonNull() View view, @NonNull() Collection<View> views, int direction)
Adds any keyboard navigation cluster roots that are descendants of
{@code view}
(including{@code view}
if it is a cluster root itself) to{@code views}
. Does nothingon API < 26.- Parameters:
views
- collection of keyboard navigation cluster roots found so far.direction
- direction to look.
-
restoreDefaultFocus
static boolean restoreDefaultFocus(@NonNull() View view)
Gives focus to the default-focus view in the view hierarchy rooted at
{@code view}
.If the default-focus view cannot be found or if API < 26, this falls back to calling requestFocus.
-
hasExplicitFocusable
static boolean hasExplicitFocusable(@NonNull() View view)
Returns true if this view is focusable or if it contains a reachable Viewfor which hasExplicitFocusable returns
{@code 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 causethis method to return true. A view set to FOCUSABLE_AUTO that resolvesto focusable will not.
-
generateViewId
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.
-
addOnUnhandledKeyEventListener
static void addOnUnhandledKeyEventListener(@NonNull() View v, @NonNull() ViewCompat.OnUnhandledKeyEventListenerCompat listener)
Adds a listener which will receive unhandled KeyEvents. This must be called on theUI thread.
- Parameters:
listener
- a receiver of unhandled KeyEvents.
-
removeOnUnhandledKeyEventListener
static void removeOnUnhandledKeyEventListener(@NonNull() View v, @NonNull() ViewCompat.OnUnhandledKeyEventListenerCompat listener)
Removes a listener which will receive unhandled KeyEvents. This must be called on theUI thread.
- Parameters:
listener
- a receiver of unhandled KeyEvents.
-
-
-
-