androidx.core.view
Interfaces
ActionProvider.VisibilityListener |
Listens to changes in visibility as reported by |
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 |
MenuHost |
A class that allows you to host and keep track of |
MenuItemCompat.OnActionExpandListener |
This interface is deprecated. Use |
MenuProvider |
Interface for indicating that a component will be supplying |
NestedScrollingChild |
This interface should be implemented by |
NestedScrollingChild2 |
This interface should be implemented by |
NestedScrollingChild3 |
This interface should be implemented by |
NestedScrollingParent |
This interface should be implemented by |
NestedScrollingParent2 |
This interface should be implemented by |
NestedScrollingParent3 |
This interface should be implemented by |
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 |
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 |
WindowInsetsAnimationControlListenerCompat |
Listener that encapsulates a request to |
WindowInsetsControllerCompat.OnControllableInsetsChangedListener |
Listener to be notified when the set of controllable |
Classes
AccessibilityDelegateCompat |
Helper for accessing |
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 |
ContentInfoCompat.Builder |
Builder for |
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 |
DragStartHelper |
DragStartHelper is a utility class for implementing drag and drop support. |
GestureDetectorCompat |
This class is deprecated. Use |
GravityCompat |
Compatibility shim for accessing newer functionality from |
HapticFeedbackConstantsCompat |
Helper class for accessing values in |
InputDeviceCompat |
Helper class for accessing values in |
LayoutInflaterCompat |
Helper for accessing features in |
MarginLayoutParamsCompat |
This class is deprecated. Use |
MenuCompat |
Helper for accessing features in |
MenuHostHelper |
Helper class for implementing |
MenuItemCompat |
Helper for accessing features in |
MotionEventCompat |
Helper for accessing features in |
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 |
RoundedCornerCompat |
Represents a rounded corner of the display. |
ScaleGestureDetectorCompat |
Helper for accessing features in |
ScrollFeedbackProviderCompat |
Compat to access |
SoftwareKeyboardControllerCompat |
Provide controls for showing and hiding the IME. |
VelocityTrackerCompat |
Helper for accessing features in |
ViewCompat |
Helper for accessing features in |
ViewConfigurationCompat |
Helper for accessing features in |
ViewGroupCompat |
Helper for accessing features in |
ViewParentCompat |
Helper for accessing features in |
ViewPropertyAnimatorCompat |
|
ViewPropertyAnimatorListenerAdapter |
This adapter class provides empty implementations of the methods from |
ViewStructureCompat |
Helper for accessing features in |
WindowCompat |
Helper for accessing features in |
WindowInsetsAnimationCompat |
Class representing an animation of a set of windows that cause insets. |
WindowInsetsAnimationCompat.BoundsCompat |
Class representing the range of an |
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.Side |
Class that defines different sides for insets. |
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 |
inline operator Boolean |
Returns |
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 |
View.drawToBitmap(config: Bitmap.Config) |
inline Unit |
Performs the given action on each item in this menu. |
inline 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 |
Returns the menu at |
operator View |
Returns the view at |
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 |
operator MutableIterator<View> |
Returns a |
inline operator Unit |
Menu.minusAssign(item: MenuItem)Removes |
inline operator Unit |
ViewGroup.minusAssign(view: View)Removes |
inline operator Unit |
ViewGroup.plusAssign(view: View)Adds |
inline Runnable |
View.postDelayed(delayInMillis: Long, crossinline action: () -> Unit)Version of |
Runnable |
View.postOnAnimationDelayed(delayInMillis: Long, action: () -> Unit)Version of |
inline Unit |
Menu.removeItemAt(index: Int)Removes the menu item at the specified index. |
inline Unit |
ViewGroup.MarginLayoutParams.setMargins(size: @Px Int)Sets the margins in the ViewGroup's MarginLayoutParams. |
inline Unit |
View.setPadding(size: @Px Int)Sets the view's padding. |
inline Unit |
View.updateLayoutParams(block: ViewGroup.LayoutParams.() -> Unit)Executes |
inline Unit |
<T : ViewGroup.LayoutParams> View.updateLayoutParams(block: T.() -> Unit)Executes |
inline Unit |
ViewGroup.MarginLayoutParams.updateMargins(Updates the margins in the |
inline Unit |
ViewGroup.MarginLayoutParams.updateMarginsRelative(Updates the relative margins in the ViewGroup's MarginLayoutParams. |
inline Unit |
Updates this view's padding. |
inline Unit |
Updates this view's relative padding. |
Extension properties summary
Sequence<View> |
Returns a |
Sequence<ViewParent> |
Returns a |
Sequence<MenuItem> |
Returns a |
Sequence<View> |
Returns a |
Sequence<View> |
Returns a |
IntRange |
Returns an |
Boolean |
Returns true when this view's visibility is |
Boolean |
Returns true when this view's visibility is |
Boolean |
Returns true when this view's visibility is |
Int |
Returns the bottom margin if this view's |
Int |
Returns the end margin if this view's |
Int |
Returns the left margin if this view's |
Int |
Returns the right margin if this view's |
Int |
Returns the start margin if this view's |
Int |
Returns the top margin if this view's |
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 |
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. |
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 ViewGroup.minusAssign(view: View): Unit
Removes view from 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 |
| See also | |
|---|---|
getLayoutParams |
|
setLayoutParams |
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 |
kotlin.ClassCastException |
If the |
| See also | |
|---|---|
getLayoutParams |
|
setLayoutParams |
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.
| See also | |
|---|---|
setPaddingRelative |
Extension properties
allViews
val View.allViews: Sequence<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.ancestors: Sequence<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 ViewGroup.children: Sequence<View>
Returns a Sequence over the immediate child views in this view group.
| See also | |
|---|---|
allViews |
|
descendants |
descendants
val ViewGroup.descendants: Sequence<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.indices: IntRange
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.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
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
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
val View.marginBottom: Int
Returns the bottom margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.
| See also | |
|---|---|
ViewGroup.MarginLayoutParams |
marginEnd
val View.marginEnd: Int
Returns the end margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.
| See also | |
|---|---|
getMarginEnd |
marginLeft
val View.marginLeft: Int
Returns the left margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.
| See also | |
|---|---|
ViewGroup.MarginLayoutParams |
marginRight
val View.marginRight: Int
Returns the right margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.
| See also | |
|---|---|
ViewGroup.MarginLayoutParams |
marginStart
val View.marginStart: Int
Returns the start margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.
| See also | |
|---|---|
getMarginStart |
marginTop
val View.marginTop: Int
Returns the top margin if this view's ViewGroup.LayoutParams is a ViewGroup.MarginLayoutParams, otherwise 0.
| See also | |
|---|---|
ViewGroup.MarginLayoutParams |