androidx.core.view

Classes

AccessibilityDelegateCompat

Helper for accessing AccessibilityDelegate.

ActionProvider

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

DisplayCutoutCompat

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

DragAndDropPermissionsCompat

Helper for accessing features in android.view.DragAndDropPermissions a backwards compatible fashion.

DragStartHelper

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

GestureDetectorCompat

Detects various gestures and events using the supplied MotionEvents.

GravityCompat

Compatibility shim for accessing newer functionality from android.view.Gravity.

InputDeviceCompat

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

LayoutInflaterCompat

Helper for accessing features in LayoutInflater.

MarginLayoutParamsCompat

Helper for accessing API features in MarginLayoutParams in a backwards compatible way.

MenuCompat

Helper for accessing features in android.view.Menu.

MenuItemCompat

Helper for accessing features in android.view.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.

NestedScrollingParentHelper

Helper class for implementing nested scrolling parent views compatible with Android platform versions earlier than Android 5.

OneShotPreDrawListener

An OnPreDrawListener that will remove itself after one OnPreDraw call.

PointerIconCompat

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

ScaleGestureDetectorCompat

Helper for accessing features in ScaleGestureDetector.

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.

WindowCompat

Helper for accessing features in Window.

WindowInsetsCompat

Describes a set of insets for window content.

Extension functions summary

For android.view.Menu
operator Boolean

Returns true if item is found in this menu.

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

Performs the given action on each item in this menu.

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

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

operator MenuItem
Menu.get(index: Int)

Returns the menu at index.

Boolean

Returns true if this menu contains no items.

Boolean

Returns true if this menu contains one or more items.

operator MutableIterator<MenuItem>

Returns a MutableIterator over the items in this menu.

operator Unit

Removes item from this menu.

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

Performs the given action when this view is laid out.

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

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

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

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

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

Return a Bitmap representation of this View.

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, crossinline action: () -> Unit)

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

Unit
View.setPadding(@Px size: Int)

Sets the view's padding.

Unit

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

Unit
View.updateLayoutParams(block: T.() -> Unit)

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

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

Updates this view's padding.

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

Updates this view's relative padding.

For android.view.ViewGroup
operator Boolean

Returns true if view is found in this view group.

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

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

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

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

operator View
ViewGroup.get(index: Int)

Returns the view at index.

Boolean

Returns true if this view group contains no views.

Boolean

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

operator MutableIterator<View>

Returns a MutableIterator over the views in this view group.

operator Unit

Removes view from this view group.

operator Unit

Adds view to this view group.

For android.view.ViewGroup.MarginLayoutParams
Unit

Sets the margins in the ViewGroup's MarginLayoutParams.

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

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

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

Updates the relative margins in the ViewGroup's MarginLayoutParams.

Extension properties summary

For android.view.Menu
Sequence<MenuItem>

Returns a Sequence over the items in this menu.

Int

Returns the number of items in this menu.

For android.view.View
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 LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.

Int

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

Int

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

Int

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

Int

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

Int

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

For android.view.ViewGroup
Sequence<View>

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

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.

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

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

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

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

Exceptions
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()
}
Return
the created Runnable

postOnAnimationDelayed

inline fun View.postOnAnimationDelayed(delayInMillis: Long, crossinline 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()
}
Return
the created Runnable

setMargins

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

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

setPadding

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

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

See Also

updateLayoutParams

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

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

updateLayoutParams

@JvmName("updateLayoutParamsTyped") inline fun <reified T : 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.

updateMargins

inline fun MarginLayoutParams.updateMargins(@Px left: Int = leftMargin, @Px top: Int = topMargin, @Px right: Int = rightMargin, @Px bottom: 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.

updateMarginsRelative

inline fun MarginLayoutParams.updateMarginsRelative(@Px start: Int = marginStart, @Px top: Int = topMargin, @Px end: Int = marginEnd, @Px bottom: 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.

updatePadding

inline fun View.updatePadding(@Px left: Int = paddingLeft, @Px top: Int = paddingTop, @Px right: Int = paddingRight, @Px bottom: 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

updatePaddingRelative

inline fun View.updatePaddingRelative(@Px start: Int = paddingStart, @Px top: Int = paddingTop, @Px end: Int = paddingEnd, @Px bottom: 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.

Extension properties

children

val Menu.children: Sequence<MenuItem>

Returns a Sequence over the items in this menu.

children

val ViewGroup.children: Sequence<View>

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

isGone

inline var View.isGone: Boolean

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

inline var View.isInvisible: Boolean

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

inline var View.isVisible: Boolean

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

inline val View.marginBottom: Int

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

marginEnd

inline val View.marginEnd: Int

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

marginLeft

inline val View.marginLeft: Int

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

marginRight

inline val View.marginRight: Int

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

marginStart

inline val View.marginStart: Int

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

marginTop

inline val View.marginTop: Int

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

size

inline val Menu.size: Int

Returns the number of items in this menu.

size

inline val ViewGroup.size: Int

Returns the number of views in this view group.