lightbulb_outline Help shape the future of the Google Play Console, Android Studio, and Firebase. Start survey

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.

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 MenuItem
Menu.get(index: Int)

Returns the menu at index.

operator Boolean

Returns true if item is found in this menu.

operator Unit

Removes item from this menu.

Boolean

Returns true if this menu contains no items.

Boolean

Returns true if this menu contains one or more items.

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 MutableIterator<MenuItem>

Returns a MutableIterator over the items in this menu.

For android.view.ViewGroup
operator View
ViewGroup.get(index: Int)

Returns the view at index.

operator Boolean

Returns true if view is found in this view group.

operator Unit

Removes view from this view group.

Boolean

Returns true if this view group contains no views.

Boolean

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

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

Returns a MutableIterator over the views in this view group.

operator Unit

Adds view to this view group.

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

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

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

Performs the given action when this view is laid out.

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

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

Unit

Sends AccessibilityEvent of type AccessibilityEvent.TYPE_ANNOUNCEMENT.

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

Updates this view's relative padding.

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

Updates this view's padding.

Unit

Sets the view's padding.

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.

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

Return a Bitmap representation of this View.

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.

For android.view.ViewGroup.MarginLayoutParams
Unit

Sets the margins in the ViewGroup's MarginLayoutParams.

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

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

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

Updates the relative margins in the ViewGroup's MarginLayoutParams.

Extension properties summary

For android.view.Menu
Int

Returns the number of items in this menu.

Sequence<MenuItem>

Returns a Sequence over the items in this menu.

For android.view.ViewGroup
Int

Returns the number of views in this view group.

Sequence<View>

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

For android.view.View
Boolean

Returns true when this view's visibility is View.VISIBLE, 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.GONE, false otherwise.

Extension functions

announceForAccessibility

inline fun View.announceForAccessibility(resource: Int): Unit

Sends AccessibilityEvent of type AccessibilityEvent.TYPE_ANNOUNCEMENT.

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.

See Also

doOnNextLayout

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

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

See Also

doOnPreDraw

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

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

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(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(size: Int): Unit

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

See Also

toBitmap

fun View.toBitmap(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.

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(left: Int = leftMargin, top: Int = topMargin, right: Int = rightMargin, 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(start: Int = marginStart, top: Int = topMargin, end: Int = marginEnd, 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(left: Int = paddingLeft, top: Int = paddingTop, right: Int = paddingRight, 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(start: Int = paddingStart, top: Int = paddingTop, end: Int = paddingEnd, 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

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.