androidx.core.view


Interfaces

ActionProvider.VisibilityListener

Listens to changes in visibility as reported by refreshVisibility.

DifferentialMotionFlingTarget

Represents an entity that may be flung by a differential motion or an entity that initiates fling on a target View.

DragStartHelper.OnDragStartListener

Interface definition for a callback to be invoked when a drag start gesture is detected.

LayoutInflaterFactory

This interface is deprecated.

Use android.view.LayoutInflater.Factory2 directly.

MenuHost

A class that allows you to host and keep track of MenuProviders that will supply android.view.MenuItems to the app bar.

MenuItemCompat.OnActionExpandListener

This interface is deprecated.

Use MenuItem.OnActionExpandListener directly.

MenuProvider

Interface for indicating that a component will be supplying MenuItems to the component owning the app bar.

NestedScrollingChild

This interface should be implemented by View subclasses that wish to support dispatching nested scrolling operations to a cooperating parent ViewGroup.

NestedScrollingChild2

This interface should be implemented by View subclasses that wish to support dispatching nested scrolling operations to a cooperating parent ViewGroup.

NestedScrollingChild3

This interface should be implemented by View subclasses that wish to support dispatching nested scrolling operations to a cooperating parent ViewGroup.

NestedScrollingParent

This interface should be implemented by ViewGroup subclasses that wish to support scrolling operations delegated by a nested child view.

NestedScrollingParent2

This interface should be implemented by ViewGroup subclasses that wish to support scrolling operations delegated by a nested child view.

NestedScrollingParent3

This interface should be implemented by ViewGroup subclasses that wish to support scrolling operations delegated by a nested child view.

OnApplyWindowInsetsListener

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

OnReceiveContentListener

Listener for apps to implement handling for insertion of content.

OnReceiveContentViewBehavior

Interface for widgets to implement default behavior for receiving content.

ScrollingView

An interface that can be implemented by Views to provide scroll related APIs.

TintableBackgroundView

Interface which allows a android.view.View to receive background tinting calls from ViewCompat when running on API v20 devices or lower.

ViewCompat.OnUnhandledKeyEventListenerCompat

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

ViewPropertyAnimatorListener

An animation listener receives notifications from an animation.

ViewPropertyAnimatorUpdateListener

Implementors of this interface can add themselves as update listeners to an ViewPropertyAnimatorCompat instance to receive callbacks on every animation frame, after the current frame's values have been calculated for that ViewPropertyAnimatorCompat.

WindowInsetsAnimationControlListenerCompat

Listener that encapsulates a request to controlWindowInsetsAnimation.

WindowInsetsControllerCompat.OnControllableInsetsChangedListener

Listener to be notified when the set of controllable WindowInsetsCompat.Type controlled by a WindowInsetsController changes.

Classes

AccessibilityDelegateCompat

Helper for accessing AccessibilityDelegate.

ActionProvider

This class is a mediator for accomplishing a given task, for example sharing a file.

ContentInfoCompat

Holds all the relevant data for a request to OnReceiveContentListener.

ContentInfoCompat.Builder

Builder for ContentInfoCompat.

DifferentialMotionFlingController

Controller differential motion flings.

DisplayCompat

A class for retrieving accurate display modes for a display.

DisplayCompat.ModeCompat

Compat class which provides access to the underlying display mode, if there is one, and a more reliable display mode size.

DisplayCutoutCompat

Represents the area of the display that is not functional for displaying content.

DragAndDropPermissionsCompat

Helper for accessing features in DragAndDropPermissions a backwards compatible fashion.

DragStartHelper

DragStartHelper is a utility class for implementing drag and drop support.

GestureDetectorCompat

This class is deprecated.

Use android.view.GestureDetector directly

GravityCompat

Compatibility shim for accessing newer functionality from Gravity.

HapticFeedbackConstantsCompat

Helper class for accessing values in android.view.HapticFeedbackConstants.

InputDeviceCompat

Helper class for accessing values in android.view.InputDevice.

LayoutInflaterCompat

Helper for accessing features in LayoutInflater.

MarginLayoutParamsCompat

This class is deprecated.

Use ViewGroup.MarginLayoutParams directly.

MenuCompat

Helper for accessing features in Menu.

MenuHostHelper

Helper class for implementing MenuHost.

MenuItemCompat

Helper for accessing features in MenuItem.

MotionEventCompat

Helper for accessing features in MotionEvent.

NestedScrollingChildHelper

Helper class for implementing nested scrolling child views compatible with Android platform versions earlier than Android 5.0 Lollipop (API 21).

NestedScrollingParentHelper

Helper class for implementing nested scrolling parent views compatible with Android platform versions earlier than Android 5.0 Lollipop (API 21).

OneShotPreDrawListener

An OnPreDrawListener that will remove itself after one OnPreDraw call.

PointerIconCompat

Helper for accessing features in PointerIcon in a backwards compatible fashion.

ScaleGestureDetectorCompat

Helper for accessing features in ScaleGestureDetector.

SoftwareKeyboardControllerCompat

Provide controls for showing and hiding the IME.

VelocityTrackerCompat

Helper for accessing features in VelocityTracker.

ViewCompat

Helper for accessing features in View.

ViewConfigurationCompat

Helper for accessing features in ViewConfiguration.

ViewGroupCompat

Helper for accessing features in ViewGroup.

ViewParentCompat

Helper for accessing features in ViewParent.

ViewPropertyAnimatorCompat
ViewPropertyAnimatorListenerAdapter

This adapter class provides empty implementations of the methods from ViewPropertyAnimatorListener.

ViewStructureCompat

Helper for accessing features in ViewStructure.

WindowCompat

Helper for accessing features in Window.

WindowInsetsAnimationCompat

Class representing an animation of a set of windows that cause insets.

WindowInsetsAnimationCompat.BoundsCompat

Class representing the range of an WindowInsetsAnimationCompat

WindowInsetsAnimationCompat.Callback

Interface that allows the application to listen to animation events for windows that cause insets.

WindowInsetsAnimationControllerCompat

Controller for app-driven animation of system windows.

WindowInsetsCompat

Describes a set of insets for window content.

WindowInsetsCompat.Builder

Builder for WindowInsetsCompat.

WindowInsetsCompat.Type

Class that defines different types of sources causing window insets.

WindowInsetsControllerCompat

Provide simple controls of windows that generate insets.

Extension functions summary

operator Boolean

Returns true if item is found in this menu.

inline operator Boolean

Returns true if view is found in this view group.

inline Unit
View.doOnAttach(crossinline action: (view: View) -> Unit)

Performs the given action when this view is attached to a window.

inline Unit
View.doOnDetach(crossinline action: (view: View) -> Unit)

Performs the given action when this view is detached from a window.

inline Unit
View.doOnLayout(crossinline action: (view: View) -> Unit)

Performs the given action when this view is laid out.

inline Unit
View.doOnNextLayout(crossinline action: (view: View) -> Unit)

Performs the given action when this view is next laid out.

inline OneShotPreDrawListener
View.doOnPreDraw(crossinline action: (view: View) -> Unit)

Performs the given action when the view tree is about to be drawn.

Bitmap

Return a Bitmap representation of this View.

inline Unit
Menu.forEach(action: (item: MenuItem) -> Unit)

Performs the given action on each item in this menu.

inline Unit
ViewGroup.forEach(action: (view: View) -> Unit)

Performs the given action on each view in this view group.

inline Unit
Menu.forEachIndexed(action: (index: Int, item: MenuItem) -> Unit)

Performs the given action on each item in this menu, providing its sequential index.

inline Unit
ViewGroup.forEachIndexed(action: (index: Int, view: View) -> Unit)

Performs the given action on each view in this view group, providing its sequential index.

inline operator MenuItem
Menu.get(index: Int)

Returns the menu at index.

operator View
ViewGroup.get(index: Int)

Returns the view at index.

inline Boolean

Returns true if this menu contains no items.

inline Boolean

Returns true if this view group contains no views.

inline Boolean

Returns true if this menu contains one or more items.

inline Boolean

Returns true if this view group contains one or more views.

operator MutableIterator<MenuItem>

Returns a MutableIterator over the items in this menu.

operator MutableIterator<View>

Returns a MutableIterator over the views in this view group.

inline operator Unit

Removes item from this menu.

inline operator Unit

Removes view from this view group.

inline operator Unit

Adds view to this view group.

inline Runnable
View.postDelayed(delayInMillis: Long, crossinline action: () -> Unit)

Version of View.postDelayed which re-orders the parameters, allowing the action to be placed outside of parentheses.

Runnable
View.postOnAnimationDelayed(delayInMillis: Long, action: () -> Unit)

Version of View.postOnAnimationDelayed which re-orders the parameters, allowing the action to be placed outside of parentheses.

inline Unit

Removes the menu item at the specified index.

inline Unit

Sets the margins in the ViewGroup's MarginLayoutParams.

inline Unit

Sets the view's padding.

inline Unit

Executes block with the View's layoutParams and reassigns the layoutParams with the updated version.

inline Unit

Executes block with a typed version of the View's layoutParams and reassigns the layoutParams with the updated version.

inline Unit
ViewGroup.MarginLayoutParams.updateMargins(
    left: @Px Int,
    top: @Px Int,
    right: @Px Int,
    bottom: @Px Int
)

Updates the margins in the ViewGroup's ViewGroup.MarginLayoutParams.

inline Unit
ViewGroup.MarginLayoutParams.updateMarginsRelative(
    start: @Px Int,
    top: @Px Int,
    end: @Px Int,
    bottom: @Px Int
)

Updates the relative margins in the ViewGroup's MarginLayoutParams.

inline Unit
View.updatePadding(left: @Px Int, top: @Px Int, right: @Px Int, bottom: @Px Int)

Updates this view's padding.

inline Unit
View.updatePaddingRelative(
    start: @Px Int,
    top: @Px Int,
    end: @Px Int,
    bottom: @Px Int
)

Updates this view's relative padding.

Extension properties summary

Sequence<View>

Returns a Sequence over this view and its descendants recursively.

Sequence<ViewParent>

Returns a Sequence of the parent chain of this view by repeatedly calling View.getParent.

Sequence<MenuItem>

Returns a Sequence over the items in this menu.

Sequence<View>

Returns a Sequence over the immediate child views in this view group.

Sequence<View>

Returns a Sequence over the child views in this view group recursively.

IntRange

Returns an IntRange of the valid indices for the children of this view group.

Boolean

Returns true when this view's visibility is View.GONE, false otherwise.

Boolean

Returns true when this view's visibility is View.INVISIBLE, false otherwise.

Boolean

Returns true when this view's visibility is View.VISIBLE, false otherwise.

Int

Returns the bottom margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

Int

Returns the end margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

Int

Returns the left margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

Int

Returns the right margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

Int

Returns the start margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

Int

Returns the top margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

Int

Returns the number of items in this menu.

Int

Returns the number of views in this view group.

Extension functions

contains

operator fun Menu.contains(item: MenuItem): Boolean

Returns true if item is found in this menu.

contains

inline operator fun ViewGroup.contains(view: View): Boolean

Returns true if view is found in this view group.

doOnAttach

inline fun View.doOnAttach(crossinline action: (view: View) -> Unit): Unit

Performs the given action when this view is attached to a window. If the view is already attached to a window the action will be performed immediately, otherwise the action will be performed after the view is next attached.

The action will only be invoked once, and any listeners will then be removed.

See also
doOnDetach

doOnDetach

inline fun View.doOnDetach(crossinline action: (view: View) -> Unit): Unit

Performs the given action when this view is detached from a window. If the view is not attached to a window the action will be performed immediately, otherwise the action will be performed after the view is detached from its current window.

The action will only be invoked once, and any listeners will then be removed.

See also
doOnAttach

doOnLayout

inline fun View.doOnLayout(crossinline action: (view: View) -> Unit): Unit

Performs the given action when this view is laid out. If the view has been laid out and it has not requested a layout, the action will be performed straight away, otherwise the action will be performed after the view is next laid out.

The action will only be invoked once on the next layout and then removed.

See also
doOnNextLayout

doOnNextLayout

inline fun View.doOnNextLayout(crossinline action: (view: View) -> Unit): Unit

Performs the given action when this view is next laid out.

The action will only be invoked once on the next layout and then removed.

See also
doOnLayout

doOnPreDraw

inline fun View.doOnPreDraw(crossinline action: (view: View) -> Unit): OneShotPreDrawListener

Performs the given action when the view tree is about to be drawn.

The action will only be invoked once prior to the next draw and then removed.

drawToBitmap

fun View.drawToBitmap(config: Bitmap.Config = Bitmap.Config.ARGB_8888): Bitmap

Return a Bitmap representation of this View.

The resulting bitmap will be the same width and height as this view's current layout dimensions. This does not take into account any transformations such as scale or translation.

Note, this will use the software rendering pipeline to draw the view to the bitmap. This may result with different drawing to what is rendered on a hardware accelerated canvas (such as the device screen).

If this view has not been laid out this method will throw a IllegalStateException.

Parameters
config: Bitmap.Config = Bitmap.Config.ARGB_8888

Bitmap config of the desired bitmap. Defaults to Bitmap.Config.ARGB_8888.

forEach

inline fun Menu.forEach(action: (item: MenuItem) -> Unit): Unit

Performs the given action on each item in this menu.

forEach

inline fun ViewGroup.forEach(action: (view: View) -> Unit): Unit

Performs the given action on each view in this view group.

forEachIndexed

inline fun Menu.forEachIndexed(action: (index: Int, item: MenuItem) -> Unit): Unit

Performs the given action on each item in this menu, providing its sequential index.

forEachIndexed

inline fun ViewGroup.forEachIndexed(action: (index: Int, view: View) -> Unit): Unit

Performs the given action on each view in this view group, providing its sequential index.

get

inline operator fun Menu.get(index: Int): MenuItem

Returns the menu at index.

Throws
kotlin.IndexOutOfBoundsException

if index is less than 0 or greater than or equal to the count.

get

operator fun ViewGroup.get(index: Int): View

Returns the view at index.

Throws
kotlin.IndexOutOfBoundsException

if index is less than 0 or greater than or equal to the count.

isEmpty

inline fun Menu.isEmpty(): Boolean

Returns true if this menu contains no items.

isEmpty

inline fun ViewGroup.isEmpty(): Boolean

Returns true if this view group contains no views.

isNotEmpty

inline fun Menu.isNotEmpty(): Boolean

Returns true if this menu contains one or more items.

isNotEmpty

inline fun ViewGroup.isNotEmpty(): Boolean

Returns true if this view group contains one or more views.

iterator

operator fun Menu.iterator(): MutableIterator<MenuItem>

Returns a MutableIterator over the items in this menu.

iterator

operator fun ViewGroup.iterator(): MutableIterator<View>

Returns a MutableIterator over the views in this view group.

minusAssign

inline operator fun Menu.minusAssign(item: MenuItem): Unit

Removes item from this menu.

minusAssign

inline operator fun ViewGroup.minusAssign(view: View): Unit

Removes view from this view group.

plusAssign

inline operator fun ViewGroup.plusAssign(view: View): Unit

Adds view to this view group.

postDelayed

inline fun View.postDelayed(delayInMillis: Long, crossinline action: () -> Unit): Runnable

Version of View.postDelayed which re-orders the parameters, allowing the action to be placed outside of parentheses.

view.postDelayed(200) {
doSomething()
}
Returns
Runnable

the created Runnable

postOnAnimationDelayed

fun View.postOnAnimationDelayed(delayInMillis: Long, action: () -> Unit): Runnable

Version of View.postOnAnimationDelayed which re-orders the parameters, allowing the action to be placed outside of parentheses.

view.postOnAnimationDelayed(16) {
doSomething()
}
Returns
Runnable

the created Runnable

removeItemAt

inline fun Menu.removeItemAt(index: Int): Unit

Removes the menu item at the specified index.

Throws
kotlin.IndexOutOfBoundsException

if index is less than 0 or greater than or equal to the count.

setMargins

inline fun ViewGroup.MarginLayoutParams.setMargins(size: @Px Int): Unit

Sets the margins in the ViewGroup's MarginLayoutParams. This version of the method sets all axes to the provided size.

See also
setMargins

setPadding

inline fun View.setPadding(size: @Px Int): Unit

Sets the view's padding. This version of the method sets all axes to the provided size.

See also
setPadding

updateLayoutParams

inline fun View.updateLayoutParams(block: ViewGroup.LayoutParams.() -> Unit): Unit

Executes block with the View's layoutParams and reassigns the layoutParams with the updated version.

Throws
kotlin.NullPointerException

If no LayoutParams is set on the view.

updateLayoutParams

inline fun <T : ViewGroup.LayoutParams> View.updateLayoutParams(block: T.() -> Unit): Unit

Executes block with a typed version of the View's layoutParams and reassigns the layoutParams with the updated version.

Throws
kotlin.NullPointerException

If no LayoutParams is set on the view.

kotlin.ClassCastException

If the LayoutParams type is not T or a subtype of T.

updateMargins

inline fun ViewGroup.MarginLayoutParams.updateMargins(
    left: @Px Int = leftMargin,
    top: @Px Int = topMargin,
    right: @Px Int = rightMargin,
    bottom: @Px Int = bottomMargin
): Unit

Updates the margins in the ViewGroup's ViewGroup.MarginLayoutParams. This version of the method allows using named parameters to just set one or more axes.

See also
setMargins

updateMarginsRelative

inline fun ViewGroup.MarginLayoutParams.updateMarginsRelative(
    start: @Px Int = marginStart,
    top: @Px Int = topMargin,
    end: @Px Int = marginEnd,
    bottom: @Px Int = bottomMargin
): Unit

Updates the relative margins in the ViewGroup's MarginLayoutParams. This version of the method allows using named parameters to just set one or more axes.

Note that this inline method references platform APIs added in API 17 and may raise runtime verification warnings on earlier platforms. See Chromium's guide to Class Verification Failures for more information.

See also
setMargins

updatePadding

inline fun View.updatePadding(
    left: @Px Int = paddingLeft,
    top: @Px Int = paddingTop,
    right: @Px Int = paddingRight,
    bottom: @Px Int = paddingBottom
): Unit

Updates this view's padding. This version of the method allows using named parameters to just set one or more axes.

See also
setPadding

updatePaddingRelative

inline fun View.updatePaddingRelative(
    start: @Px Int = paddingStart,
    top: @Px Int = paddingTop,
    end: @Px Int = paddingEnd,
    bottom: @Px Int = paddingBottom
): Unit

Updates this view's relative padding. This version of the method allows using named parameters to just set one or more axes.

Note that this inline method references platform APIs added in API 17 and may raise runtime verification warnings on earlier platforms. See Chromium's guide to Class Verification Failures for more information.

Extension properties

allViews

val View.allViewsSequence<View>

Returns a Sequence over this view and its descendants recursively. This is a depth-first traversal similar to View.findViewById. A view with no children will return a single-element sequence of itself.

See also
descendants

ancestors

val View.ancestorsSequence<ViewParent>

Returns a Sequence of the parent chain of this view by repeatedly calling View.getParent. An unattached view will return a zero-element sequence.

See also
descendants

children

val Menu.childrenSequence<MenuItem>

Returns a Sequence over the items in this menu.

children

val ViewGroup.childrenSequence<View>

Returns a Sequence over the immediate child views in this view group.

descendants

val ViewGroup.descendantsSequence<View>

Returns a Sequence over the child views in this view group recursively.

This performs a depth-first traversal. A view with no children will return a zero-element sequence.

For example, to efficiently filter views within the hierarchy using a predicate:

fun ViewGroup.findViewTreeIterator(predicate: (View) -> Boolean): Sequence<View> {
return sequenceOf(this)
.plus(descendantsTree)
.filter { predicate(it) }
}

indices

val ViewGroup.indicesIntRange

Returns an IntRange of the valid indices for the children of this view group.

This can be used for looping:

for (i in viewGroup.indices.reversed) {
if (viewGroup[i] is SomeView) {
viewGroup.removeViewAt(i)
}
}

Or to determine if an index is valid:

if (2 in viewGroup.indices) {
// Do something…
}

isGone

var View.isGoneBoolean

Returns true when this view's visibility is View.GONE, false otherwise.

if (view.isGone) {
// Behavior...
}

Setting this property to true sets the visibility to View.GONE, false to View.VISIBLE.

view.isGone = true

isInvisible

var View.isInvisibleBoolean

Returns true when this view's visibility is View.INVISIBLE, false otherwise.

if (view.isInvisible) {
// Behavior...
}

Setting this property to true sets the visibility to View.INVISIBLE, false to View.VISIBLE.

view.isInvisible = true

isVisible

var View.isVisibleBoolean

Returns true when this view's visibility is View.VISIBLE, false otherwise.

if (view.isVisible) {
// Behavior...
}

Setting this property to true sets the visibility to View.VISIBLE, false to View.GONE.

view.isVisible = true

marginBottom

val View.marginBottomInt

Returns the bottom margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

marginEnd

val View.marginEndInt

Returns the end margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

See also
getMarginEnd

marginLeft

val View.marginLeftInt

Returns the left margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

marginRight

val View.marginRightInt

Returns the right margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

marginStart

val View.marginStartInt

Returns the start margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

See also
getMarginStart

marginTop

val View.marginTopInt

Returns the top margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

size

val Menu.sizeInt

Returns the number of items in this menu.

size

val ViewGroup.sizeInt

Returns the number of views in this view group.