androidx.activity
依赖项
Groovy
dependencies { implementation "androidx.activity:activity-ktx:1.13.0" }
Kotlin
dependencies { implementation("androidx.activity:activity-ktx:1.13.0") }
扩展函数
针对 OnBackPressedDispatcher
| OnBackPressedCallback |
OnBackPressedDispatcher.addCallback(owner: LifecycleOwner? = null, enabled: Boolean = true, onBackPressed: OnBackPressedCallback.() -> Unit)
创建并添加一个新的 OnBackPressedCallback,它会在 OnBackPressedCallback.handleOnBackPressed 中调用 onBackPressed。 |
针对 ComponentActivity
| Lazy<VM> |
ComponentActivity.viewModels(noinline factoryProducer: () -> ViewModelProvider.Factory = null)
返回一个用于访问 ComponentActivity 的 ViewModel 的 Lazy 委托;如果指定了 factoryProducer,则它返回的 ViewModelProvider.Factory 将用于首次创建 ViewModel。 |
androidx.benchmark
依赖项
Groovy
dependencies { implementation "androidx.benchmark:benchmark-junit4:1.4.1" }
Kotlin
dependencies { implementation("androidx.benchmark:benchmark-junit4:1.4.1") }
顶层函数
| Unit |
beginTraceSection(sectionName: String)
|
| Unit |
endTraceSection()
|
androidx.benchmark.junit4
依赖项
Groovy
dependencies { implementation "androidx.benchmark:benchmark-junit4:1.4.1" }
Kotlin
dependencies { implementation("androidx.benchmark:benchmark-junit4:1.4.1") }
扩展函数
针对 BenchmarkRule
| Unit |
BenchmarkRule.measureRepeated(crossinline block: BenchmarkRule.Scope.() -> Unit)
基准测试一段代码。 |
androidx.collection
依赖项
Groovy
dependencies { implementation "androidx.collection:collection-ktx:1.6.0" }
Kotlin
dependencies { implementation("androidx.collection:collection-ktx:1.6.0") }
扩展函数
针对 LongSparseArray
| operator Boolean |
LongSparseArray<T>.contains(key: Long)
如果集合包含 key,则返回 true。 |
| Unit |
LongSparseArray<T>.forEach(action: (key: Long, value: T) -> Unit)
对每个键值对条目执行给定的 action。 |
| T |
LongSparseArray<T>.getOrDefault(key: Long, defaultValue: T)
返回与 key 对应的值;如果不存在,则返回 defaultValue。 |
| T |
LongSparseArray<T>.getOrElse(key: Long, defaultValue: () -> T)
返回与 key 对应的值;如果不存在,则返回从 defaultValue 获取的值。 |
| Boolean |
LongSparseArray<T>.isNotEmpty()
当集合包含元素时返回 true。 |
| LongIterator |
LongSparseArray<T>.keyIterator()
返回一个遍历集合键的迭代器。 |
| operator LongSparseArray<T> |
LongSparseArray<T>.plus(other: LongSparseArray<T>)
通过添加或替换来自 other 的条目来创建新集合。 |
| Boolean |
LongSparseArray<T>.remove(key: Long, value: T)
|
| operator Unit |
LongSparseArray<T>.set(key: Long, value: T)
允许使用索引运算符在集合中存储值。 |
| Iterator<T> |
LongSparseArray<T>.valueIterator()
返回一个遍历集合值的迭代器。 |
针对 SparseArrayCompat
| operator Boolean |
SparseArrayCompat<T>.contains(key: Int)
如果集合包含 key,则返回 true。 |
| Unit |
SparseArrayCompat<T>.forEach(action: (key: Int, value: T) -> Unit)
对每个键值对条目执行给定的 action。 |
| T |
SparseArrayCompat<T>.getOrDefault(key: Int, defaultValue: T)
返回与 key 对应的值;如果不存在,则返回 defaultValue。 |
| T |
SparseArrayCompat<T>.getOrElse(key: Int, defaultValue: () -> T)
返回与 key 对应的值;如果不存在,则返回从 defaultValue 获取的值。 |
| Boolean |
SparseArrayCompat<T>.isNotEmpty()
当集合包含元素时返回 true。 |
| IntIterator |
SparseArrayCompat<T>.keyIterator()
返回一个遍历集合键的迭代器。 |
| operator SparseArrayCompat<T> |
SparseArrayCompat<T>.plus(other: SparseArrayCompat<T>)
通过添加或替换来自 other 的条目来创建新集合。 |
| Boolean |
SparseArrayCompat<T>.remove(key: Int, value: T)
|
| operator Unit |
SparseArrayCompat<T>.set(key: Int, value: T)
允许使用索引运算符在集合中存储值。 |
| Iterator<T> |
SparseArrayCompat<T>.valueIterator()
返回一个遍历集合值的迭代器。 |
扩展属性
针对 LongSparseArray
| Int |
LongSparseArray<T>.size()
返回集合中键值对的数量。 |
针对 SparseArrayCompat
| Int |
SparseArrayCompat<T>.size()
返回集合中键值对的数量。 |
顶层函数
| ArrayMap<K, V> |
arrayMapOf()
返回一个新的空 ArrayMap。 |
| ArrayMap<K, V> |
arrayMapOf(vararg pairs: Pair<K, V>)
返回一个新的 ArrayMap,其中包含指定的条目(以键值对列表形式提供,其中第一部分是键,第二部分是值)。 |
| ArraySet<T> |
arraySetOf()
返回一个新的空 ArraySet。 |
| ArraySet<T> |
arraySetOf(vararg values: T)
返回一个新的包含指定内容的 ArraySet。 |
| LruCache<K, V> |
lruCache(maxSize: Int, crossinline sizeOf: (key: K, value: V) -> Int = { _, _ -> 1 }, crossinline create: (key: K) -> V? = { null as V? }, crossinline onEntryRemoved: (evicted: Boolean, key: K, oldValue: V, newValue: V?) -> Unit = { _, _, _, _ -> })
使用给定参数创建一个 LruCache。 |
androidx.core.animation
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.19.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.19.0") }
扩展函数
针对 android.animation.Animator
| AnimatorListener |
Animator.addListener(crossinline onEnd: (animator: Animator) -> Unit = {}, crossinline onStart: (animator: Animator) -> Unit = {}, crossinline onCancel: (animator: Animator) -> Unit = {}, crossinline onRepeat: (animator: Animator) -> Unit = {})
使用提供的操作为此 Animator 添加一个监听器。 |
| AnimatorPauseListener |
Animator.addPauseListener(crossinline onResume: (animator: Animator) -> Unit = {}, crossinline onPause: (animator: Animator) -> Unit = {})
使用提供的操作为此 Animator 添加一个暂停和恢复监听器。 |
| AnimatorListener |
Animator.doOnCancel(crossinline action: (animator: Animator) -> Unit)
添加一个在动画被取消时调用的操作。 |
| AnimatorListener |
Animator.doOnEnd(crossinline action: (animator: Animator) -> Unit)
添加一个在动画结束时调用的操作。 |
| AnimatorPauseListener |
Animator.doOnPause(crossinline action: (animator: Animator) -> Unit)
添加一个在动画被暂停时调用的操作。 |
| AnimatorListener |
Animator.doOnRepeat(crossinline action: (animator: Animator) -> Unit)
添加一个在动画重复时调用的操作。 |
| AnimatorPauseListener |
Animator.doOnResume(crossinline action: (animator: Animator) -> Unit)
添加一个在动画暂停后恢复时调用的操作。 |
| AnimatorListener |
Animator.doOnStart(crossinline action: (animator: Animator) -> Unit)
添加一个在动画开始时调用的操作。 |
androidx.core.content
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.19.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.19.0") }
扩展函数
针对 android.content.Context
| T? |
Context.getSystemService()
按类返回系统级服务的句柄。 |
| Unit |
Context.withStyledAttributes(set: AttributeSet? = null, attrs: IntArray, @AttrRes defStyleAttr: Int = 0, @StyleRes defStyleRes: Int = 0, block: TypedArray.() -> Unit)
在 TypedArray 接收器上执行 block。 |
| Unit |
Context.withStyledAttributes(@StyleRes resourceId: Int, attrs: IntArray, block: TypedArray.() -> Unit)
在 TypedArray 接收器上执行 block。 |
针对 android.content.SharedPreferences
| Unit |
SharedPreferences.edit(: Boolean = false, : Editor.() -> Unit)
|
顶层函数
| ContentValues |
contentValuesOf(vararg pairs: Pair<String, Any?>)
返回一个包含给定键值对作为元素的新 ContentValues。 |
androidx.core.content.res
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.19.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.19.0") }
扩展函数
针对 android.content.res.TypedArray
androidx.core.database
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.19.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.19.0") }
扩展函数
针对 android.database.Cursor
| ByteArray? |
Cursor.getBlobOrNull(index: Int)
以可为空的字节数组形式返回请求列的值。 |
| Double? |
Cursor.getDoubleOrNull(index: Int)
以可为空的双精度浮点数形式返回请求列的值。 |
| Float? |
Cursor.getFloatOrNull(index: Int)
以可为空的浮点数形式返回请求列的值。 |
| Int? |
Cursor.getIntOrNull(index: Int)
以可为空的整数形式返回请求列的值。 |
| Long? |
Cursor.getLongOrNull(index: Int)
以可为空的长整数形式返回请求列的值。 |
| Short? |
Cursor.getShortOrNull(index: Int)
以可为空的短整数形式返回请求列的值。 |
| String? |
Cursor.getStringOrNull(index: Int)
以可为空的字符串形式返回请求列的值。 |
androidx.core.database.sqlite
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.19.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.19.0") }
扩展函数
针对 android.database.sqlite.SQLiteDatabase
| T |
SQLiteDatabase.transaction(exclusive: Boolean = true, body: SQLiteDatabase.() -> T)
在一个事务中运行 body,如果它在没有异常的情况下完成,则将其标记为成功。 |
androidx.core.graphics
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.19.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.19.0") }
扩展函数
针对 android.graphics.Bitmap
| Bitmap |
Bitmap.applyCanvas(block: Canvas.() -> Unit)
|
| operator Boolean |
Bitmap.contains(p: Point)
如果指定点在位图内,则返回 true。 |
| operator Boolean |
Bitmap.contains(p: PointF)
如果指定点在位图内,则返回 true。 |
| operator Int |
Bitmap.get(x: Int, y: Int)
返回指定位置的像素值。 |
| Bitmap |
Bitmap.scale(width: Int, height: Int, filter: Boolean = true)
在可能的情况下,创建一个从此位图缩放出来的新位图。 |
| operator Unit |
Bitmap.set(x: Int, y: Int, color: Int)
将指定的 颜色整数 写入位图(假设它是可变的)的指定 |
针对 android.graphics.Canvas
针对 android.graphics.Color
| operator Float |
Color.component1()
返回颜色的第一个分量。 |
| operator Float |
Color.component2()
返回颜色的第二个分量。 |
| operator Float |
Color.component3()
返回颜色的第三个分量。 |
| operator Float |
Color.component4()
返回颜色的第四个分量。 |
| infix Color! |
Color.convertTo(colorSpace: Named)
将颜色接收器转换为指定色彩空间中的颜色。 |
| infix Color! |
Color.convertTo(colorSpace: ColorSpace)
将颜色接收器转换为指定色彩空间中的颜色。 |
| operator Color |
Color.plus(c: Color)
将两个半透明颜色合成在一起。 |
针对 android.graphics.ImageDecoder.Source
| Bitmap |
Source.decodeBitmap(crossinline action: ImageDecoder.(info: ImageInfo, source: Source) -> Unit)
从 Source 创建位图 |
| Drawable |
Source.decodeDrawable(crossinline action: ImageDecoder.(info: ImageInfo, source: Source) -> Unit)
从 Source 创建 Drawable |
针对 android.graphics.Matrix
| operator Matrix |
Matrix.times(m: Matrix)
将此 Matrix 与另一个矩阵相乘,并以新矩阵的形式返回结果。 |
| FloatArray |
Matrix.values()
以新的浮点数组形式返回此 Matrix 的 9 个值。 |
针对 android.graphics.Paint
| Boolean |
Paint.setBlendMode(blendModeCompat: BlendModeCompat?)
以向后兼容的方式配置 Paint 的 BlendMode 的便捷方法。 |
针对 android.graphics.Path
| infix Path |
Path.and(p: Path)
将两个路径的交集作为新的 Path 返回。 |
| Iterable<PathSegment> |
Path.flatten(error: Float = 0.5f)
用一系列线段展平(或近似)Path。 |
| operator Path |
Path.minus(p: Path)
将两个路径的差集作为新的 Path 返回。 |
| infix Path |
Path.or(p: Path)
将两个路径的并集作为新的 Path 返回。 |
| operator Path |
Path.plus(p: Path)
将两个路径的并集作为新的 Path 返回。 |
| infix Path |
Path.xor(p: Path)
将两个路径的并集减去交集作为新的 Path 返回。 |
针对 android.graphics.Picture
| Picture |
Picture.record(width: Int, height: Int, block: Canvas.() -> Unit)
创建一个新的 Canvas 以在 Picture 中记录命令,在新建的画布上执行指定的 block,并返回此 Picture。 |
针对 android.graphics.Point
| operator Int |
Point.component1()
返回此点的 x 坐标。 |
| operator Int |
Point.component2()
返回此点的 y 坐标。 |
| operator Point |
Point.minus(p: Point)
通过取指定点的相反值来偏移此点,并将结果作为新点返回。 |
| operator Point |
Point.minus(xy: Int)
通过取指定量的相反值在 X 和 Y 轴上偏移此点,并将结果作为新点返回。 |
| operator Point |
Point.plus(p: Point)
通过指定点偏移此点,并将结果作为新点返回。 |
| operator Point |
Point.plus(xy: Int)
通过指定量在 X 和 Y 轴上偏移此点,并将结果作为新点返回。 |
| PointF |
Point.toPointF()
返回此点的 PointF 表示形式。 |
| operator Point |
Point.unaryMinus()
返回一个表示此点相反值的新点。 |
针对 android.graphics.PointF
| operator Float |
PointF.component1()
返回此点的 x 坐标。 |
| operator Float |
PointF.component2()
返回此点的 y 坐标。 |
| operator PointF |
PointF.minus(p: PointF)
通过取指定点的相反值来偏移此点,并将结果作为新点返回。 |
| operator PointF |
PointF.minus(xy: Float)
通过取指定量的相反值在 X 和 Y 轴上偏移此点,并将结果作为新点返回。 |
| operator PointF |
PointF.plus(p: PointF)
通过指定点偏移此点,并将结果作为新点返回。 |
| operator PointF |
PointF.plus(xy: Float)
通过指定量在 X 和 Y 轴上偏移此点,并将结果作为新点返回。 |
| Point |
PointF.toPoint()
返回此点的 Point 表示形式。 |
| operator PointF |
PointF.unaryMinus()
返回一个表示此点相反值的新点。 |
针对 android.graphics.PorterDuff.Mode
| PorterDuffColorFilter |
Mode.toColorFilter(color: Int)
创建一个新的 PorterDuffColorFilter,它使用此 PorterDuff.Mode 作为 alpha 合成或混合模式,并使用指定的 color。 |
| PorterDuffXfermode |
Mode.toXfermode()
创建一个新的 PorterDuffXfermode,它使用此 PorterDuff.Mode 作为 alpha 合成或混合模式。 |
针对 android.graphics.Rect
| infix Rect |
Rect.and(r: Rect)
将两个矩形的交集作为新矩形返回。 |
| operator Int |
Rect.component1()
返回矩形的第一个分量“left”。 |
| operator Int |
Rect.component2()
返回矩形的第二个分量“top”。 |
| operator Int |
Rect.component3()
返回矩形的第三个分量“right”。 |
| operator Int |
Rect.component4()
返回矩形的第四个分量“bottom”。 |
| operator Boolean |
Rect.contains(p: Point)
如果指定点在矩形内,则返回 true。 |
| operator Region |
Rect.minus(r: Rect)
将此矩形与指定矩形的差集作为新区域返回。 |
| operator Rect |
Rect.minus(xy: Int)
返回一个新的矩形,表示此矩形在 X 和 Y 轴上偏移指定量的相反值。 |
| operator Rect |
Rect.minus(xy: Point)
返回一个新的矩形,表示此矩形偏移指定点的相反值。 |
| infix Rect |
Rect.or(r: Rect)
将两个矩形的并集作为新矩形返回。 |
| operator Rect |
Rect.plus(r: Rect)
执行此矩形与指定矩形的并集,并将结果作为新矩形返回。 |
| operator Rect |
Rect.plus(xy: Int)
返回一个新的矩形,表示此矩形在 X 和 Y 轴上偏移指定量。 |
| operator Rect |
Rect.plus(xy: Point)
返回一个新的矩形,表示此矩形偏移指定点。 |
| operator Rect |
Rect.times(factor: Int)
返回一个新的矩形,表示此矩形的各个分量均按 factor 进行缩放。 |
| RectF |
Rect.toRectF()
返回此矩形的 RectF 表示形式。 |
| Region |
Rect.toRegion()
返回此矩形的 Region 表示形式。 |
| infix Region |
Rect.xor(r: Rect)
将两个矩形的并集减去交集作为新区域返回。 |
针对 android.graphics.RectF
| infix RectF |
RectF.and(r: RectF)
将两个矩形的交集作为新矩形返回。 |
| operator Float |
RectF.component1()
返回矩形的第一个分量“left”。 |
| operator Float |
RectF.component2()
返回矩形的第二个分量“top”。 |
| operator Float |
RectF.component3()
返回矩形的第三个分量“right”。 |
| operator Float |
RectF.component4()
返回矩形的第四个分量“bottom”。 |
| operator Boolean |
RectF.contains(p: PointF)
如果指定点在矩形内,则返回 true。 |
| operator Region |
RectF.minus(r: RectF)
将此矩形与指定矩形的差集作为新区域返回。 |
| operator RectF |
RectF.minus(xy: Float)
返回一个新的矩形,表示此矩形在 X 和 Y 轴上偏移指定量的相反值。 |
| operator RectF |
RectF.minus(xy: PointF)
返回一个新的矩形,表示此矩形偏移指定点的相反值。 |
| infix RectF |
RectF.or(r: RectF)
将两个矩形的并集作为新矩形返回。 |
| operator RectF |
RectF.plus(r: RectF)
执行此矩形与指定矩形的并集,并将结果作为新矩形返回。 |
| operator RectF |
RectF.plus(xy: Float)
返回一个新的矩形,表示此矩形在 X 和 Y 轴上偏移指定量。 |
| operator RectF |
RectF.plus(xy: PointF)
返回一个新的矩形,表示此矩形偏移指定点。 |
| operator RectF |
RectF.times(factor: Int)
返回一个新的矩形,表示此矩形的各个分量均按 factor 进行缩放。 |
| operator RectF |
RectF.times(factor: Float)
返回一个新的矩形,表示此矩形的各个分量均按 factor 进行缩放。 |
| Rect |
RectF.toRect()
返回此矩形的 Rect 表示形式。 |
| Region |
RectF.toRegion()
返回此矩形的 Region 表示形式。 |
| RectF |
RectF.transform(m: Matrix)
使用提供的 Matrix 原地变换此矩形,并返回此矩形。 |
| infix Region |
RectF.xor(r: RectF)
将两个矩形的并集减去交集作为新区域返回。 |
针对 android.graphics.Region
| infix Region |
Region.and(r: Rect)
将此区域与指定 Rect 的交集作为新区域返回。 |
| infix Region |
Region.and(r: Region)
将此区域与指定区域的交集作为新区域返回。 |
| operator Boolean |
Region.contains(p: Point)
如果区域包含指定 Point,则返回 true。 |
| Unit |
Region.forEach(action: (rect: Rect) -> Unit)
对此区域中的每个矩形执行给定的操作。 |
| operator Iterator<Rect> |
Region.iterator()
返回遍历此区域中矩形的 Iterator。 |
| operator Region |
Region.minus(r: Rect)
将此区域与指定 Rect 的差集作为新区域返回。 |
| operator Region |
Region.minus(r: Region)
将此区域与指定区域的差集作为新区域返回。 |
| operator Region |
Region.not()
将此区域的求反结果作为新区域返回。 |
| infix Region |
Region.or(r: Rect)
将此区域与指定 Rect 的并集作为新区域返回。 |
| infix Region |
Region.or(r: Region)
将此区域与指定区域的并集作为新区域返回。 |
| operator Region |
Region.plus(r: Rect)
将此区域与指定 Rect 的并集作为新区域返回。 |
| operator Region |
Region.plus(r: Region)
将此区域与指定区域的并集作为新区域返回。 |
| operator Region |
Region.unaryMinus()
将此区域的求反结果作为新区域返回。 |
| infix Region |
Region.xor(r: Rect)
将此区域与指定 Rect 的并集减去交集作为新区域返回。 |
| infix Region |
Region.xor(r: Region)
将此区域与指定区域的并集减去交集作为新区域返回。 |
针对 android.graphics.Shader
| Unit |
Shader.transform(block: Matrix.() -> Unit)
将指定的 block 包装在 Shader.getLocalMatrix 和 Shader.setLocalMatrix 的调用中。 |
针对 kotlin.Int
| operator Int |
Int.component1()
返回颜色整数的 alpha 分量。 |
| operator Int |
Int.component2()
返回颜色整数的红色分量。 |
| operator Int |
Int.component3()
返回颜色整数的绿色分量。 |
| operator Int |
Int.component4()
返回颜色整数的蓝色分量。 |
| infix Long |
Int.convertTo(colorSpace: Named)
将颜色整数接收器转换为指定色彩空间中的颜色长整数。 |
| infix Long |
Int.convertTo(colorSpace: ColorSpace)
将颜色整数接收器转换为指定色彩空间中的颜色长整数。 |
| Color |
Int.toColor()
从颜色整数创建一个新的 Color 实例。 |
| Long |
Int.toColorLong()
|
针对 kotlin.Long
| operator Float |
Long.component1()
返回颜色的第一个分量。 |
| operator Float |
Long.component2()
返回颜色的第二个分量。 |
| operator Float |
Long.component3()
返回颜色的第三个分量。 |
| operator Float |
Long.component4()
返回颜色的第四个分量。 |
| infix Long |
Long.convertTo(colorSpace: Named)
将颜色长整数接收器转换为指定色彩空间中的颜色长整数。 |
| infix Long |
Long.convertTo(colorSpace: ColorSpace)
将颜色长整数接收器转换为指定色彩空间中的颜色长整数。 |
| Color |
Long.toColor()
|
| Int |
Long.toColorInt()
|
针对 kotlin.String
| Int |
String.toColorInt()
|
扩展属性
针对 kotlin.Int
| Int |
Int.alpha()
返回颜色整数的 alpha 分量。 |
| Int |
Int.blue()
返回颜色整数的蓝色分量。 |
| Int |
Int.green()
返回颜色整数的绿色分量。 |
| Float |
Int.luminance()
假设使用 sRGB 编码,返回颜色整数的相对亮度。 |
| Int |
Int.red()
返回颜色整数的红色分量。 |
针对 kotlin.Long
| Float |
Long.alpha()
返回颜色长整数的 alpha 分量。 |
| Float |
Long.blue()
返回颜色长整数的蓝色分量。 |
| ColorSpace |
Long.colorSpace()
返回编码在指定颜色长整数中的色彩空间。 |
| Float |
Long.green()
返回颜色长整数的绿色分量。 |
| Boolean |
Long.isSrgb()
指示颜色是否在 sRGB 色彩空间中。 |
| Boolean |
Long.isWideGamut()
指示颜色是否在 广色域 色彩空间中。 |
| Float |
Long.luminance()
返回颜色的相对亮度。 |
| Float |
Long.red()
返回颜色长整数的红色分量。 |
顶层函数
| Bitmap |
createBitmap(width: Int, height: Int, config: Config = Bitmap.Config.ARGB_8888)
|
| Bitmap |
createBitmap(width: Int, height: Int, config: Config = Bitmap.Config.ARGB_8888, hasAlpha: Boolean = true, colorSpace: ColorSpace = ColorSpace.get(ColorSpace.Named.SRGB))
|
| Matrix |
rotationMatrix(degrees: Float, px: Float = 0.0f, py: Float = 0.0f)
|
| Matrix |
scaleMatrix(sx: Float = 1.0f, sy: Float = 1.0f)
|
| Matrix |
translationMatrix(tx: Float = 0.0f, ty: Float = 0.0f)
|
androidx.core.graphics.drawable
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.19.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.19.0") }
扩展函数
针对 android.graphics.Bitmap
| Icon |
Bitmap.toAdaptiveIcon()
|
| BitmapDrawable |
Bitmap.toDrawable(resources: Resources)
从此 Bitmap 创建 BitmapDrawable。 |
| Icon |
Bitmap.toIcon()
|
针对 android.graphics.Color
| ColorDrawable |
Color.toDrawable()
从此 Color 创建 ColorDrawable(通过 Color.toArgb)。 |
针对 android.graphics.drawable.Drawable
| Bitmap |
Drawable.toBitmap(@Px width: Int = intrinsicWidth, @Px height: Int = intrinsicHeight, config: Config? = null)
|
| Unit |
Drawable.updateBounds(@Px left: Int = bounds.left, @Px top: Int = bounds.top, @Px right: Int = bounds.right, @Px bottom: Int = bounds.bottom)
更新此 Drawable 的边界。 |
针对 android.net.Uri
| Icon |
Uri.toIcon()
|
针对 kotlin.ByteArray
| Icon |
ByteArray.toIcon()
|
针对 kotlin.Int
| ColorDrawable |
Int.toDrawable()
从此颜色值创建 ColorDrawable。 |
androidx.core.location
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.19.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.19.0") }
扩展函数
针对 android.location.Location
| operator Double |
Location.component1()
返回此 Location 的纬度。 |
| operator Double |
Location.component2()
返回此 Location 的经度。 |
androidx.core.net
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.19.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.19.0") }
扩展函数
针对 android.net.Uri
| File |
Uri.toFile()
|
针对 java.io.File
| Uri |
File.toUri()
从给定的文件创建 Uri。 |
针对 kotlin.String
| Uri |
String.toUri()
从给定的已编码 URI 字符串创建 Uri。 |
androidx.core.os
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.19.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.19.0") }
扩展函数
针对 android.os.Handler
| Runnable |
Handler.postAtTime(uptimeMillis: Long, token: Any? = null, crossinline action: () -> Unit)
Handler.postAtTime 的版本,它重排了参数,允许将操作放在括号外。 |
| Runnable |
Handler.postDelayed(delayInMillis: Long, token: Any? = null, crossinline action: () -> Unit)
Handler.postDelayed 的版本,它重排了参数,允许将操作放在括号外。 |
顶层函数
| Bundle |
bundleOf(vararg pairs: Pair<String, Any?>)
返回一个新的 Bundle,其中包含给定的键/值对作为元素。 |
| PersistableBundle |
persistableBundleOf(vararg pairs: Pair<String, Any?>)
返回一个新的 PersistableBundle,其中包含给定的键/值对作为元素。 |
| T |
trace(sectionName: String, block: () -> T)
将指定的 block 包装在 Trace.beginSection(使用提供的 sectionName)和 Trace.endSection 的调用中。 |
androidx.core.text
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.19.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.19.0") }
扩展函数
针对 android.text.Spannable
| Unit |
Spannable.clearSpans()
清除此文本中的所有 span。 |
| operator Unit |
Spannable.set(start: Int, end: Int, span: Any)
|
| operator Unit |
Spannable.set(range: IntRange, span: Any)
|
针对 android.text.SpannableStringBuilder
针对 android.text.Spanned
| Array<out T> |
Spanned.getSpans(start: Int = 0, end: Int = length)
获取所有属于 T 实例的 span。 |
| String |
Spanned.toHtml(option: Int = TO_HTML_PARAGRAPH_LINES_CONSECUTIVE)
从该 Spanned 的 span 返回一个 HTML 字符串。 |
针对 kotlin.CharSequence
| Boolean |
CharSequence.isDigitsOnly()
返回给定的 CharSequence 是否仅包含数字。 |
| Spannable |
CharSequence.toSpannable()
返回一个新的 Spannable(基于该 CharSequence),或者如果源本身已经是 SpannableString 的实例,则返回源本身。 |
| Spanned |
CharSequence.toSpanned()
返回一个新的 Spanned(基于该 CharSequence),或者如果源本身已经是 SpannedString 的实例,则返回源本身。 |
| Int |
CharSequence.trimmedLength()
返回指定的 CharSequence 在去除开头和结尾的空格及 ASCII 控制字符(如 String.trim 所做的)后的长度。 |
针对 kotlin.String
| String |
String.htmlEncode()
对字符串进行 HTML 编码。 |
| Spanned |
String.parseAsHtml(flags: Int = FROM_HTML_MODE_LEGACY, imageGetter: ImageGetter? = null, tagHandler: TagHandler? = null)
通过将此字符串解析为 HTML 返回一个 Spanned。 |
扩展属性
针对 java.util.Locale
| Int |
Locale.layoutDirection()
返回给定语言区域的布局方向。 |
顶层函数
| SpannedString |
buildSpannedString(builderAction: SpannableStringBuilder.() -> Unit)
通过使用提供的 builderAction 填充新创建的 SpannableStringBuilder,然后将其转换为 SpannedString 来构建新字符串。 |
androidx.core.transition
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.19.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.19.0") }
扩展函数
针对 android.transition.Transition
| TransitionListener |
Transition.addListener(crossinline onEnd: (transition: Transition) -> Unit = {}, crossinline onStart: (transition: Transition) -> Unit = {}, crossinline onCancel: (transition: Transition) -> Unit = {}, crossinline onResume: (transition: Transition) -> Unit = {}, crossinline onPause: (transition: Transition) -> Unit = {})
使用提供的操作为此 Transition 添加监听器。 |
| TransitionListener |
Transition.doOnCancel(crossinline action: (transition: Transition) -> Unit)
添加一个在此转换被取消时调用的操作。 |
| TransitionListener |
Transition.doOnEnd(crossinline action: (transition: Transition) -> Unit)
添加一个在此转换结束时调用的操作。 |
| TransitionListener |
Transition.doOnPause(crossinline action: (transition: Transition) -> Unit)
添加一个在此转换暂停时调用的操作。 |
| TransitionListener |
Transition.doOnResume(crossinline action: (transition: Transition) -> Unit)
添加一个在此转换暂停后恢复时调用的操作。 |
| TransitionListener |
Transition.doOnStart(crossinline action: (transition: Transition) -> Unit)
添加一个在此转换开始时调用的操作。 |
androidx.core.util
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.19.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.19.0") }
扩展函数
针对 android.util.AtomicFile
| ByteArray |
AtomicFile.readBytes()
将此文件的全部内容作为字节数组获取。 |
| String |
AtomicFile.readText(charset: Charset = Charsets.UTF_8)
使用 UTF-8 或指定的 charset 将此文件的全部内容获取为字符串。 |
| Unit |
AtomicFile.tryWrite(block: (out: FileOutputStream) -> Unit)
在此文件上执行 block 内的写入操作。 |
| Unit |
AtomicFile.writeBytes(array: ByteArray)
将此文件的内容设置为字节 array。 |
| Unit |
AtomicFile.writeText(text: String, charset: Charset = Charsets.UTF_8)
|
针对 android.util.LongSparseArray
| operator Boolean |
LongSparseArray<T>.contains(key: Long)
如果集合包含 key,则返回 true。 |
| Boolean |
LongSparseArray<T>.containsKey(key: Long)
如果集合包含 key,则返回 true。 |
| Boolean |
LongSparseArray<T>.containsValue(value: T)
如果集合包含 value,则返回 true。 |
| Unit |
LongSparseArray<T>.forEach(action: (key: Long, value: T) -> Unit)
对每个键/值条目执行给定的 action。 |
| T |
LongSparseArray<T>.getOrDefault(key: Long, defaultValue: T)
返回对应于 key 的值,如果不存在,则返回 defaultValue。 |
| T |
LongSparseArray<T>.getOrElse(key: Long, defaultValue: () -> T)
返回对应于 key 的值,如果不存在,则返回 defaultValue 的计算结果。 |
| Boolean |
LongSparseArray<T>.isEmpty()
当集合不包含任何元素时返回 true。 |
| Boolean |
LongSparseArray<T>.isNotEmpty()
当集合包含元素时返回 true。 |
| LongIterator |
LongSparseArray<T>.keyIterator()
返回一个遍历集合键的迭代器。 |
| operator LongSparseArray<T> |
LongSparseArray<T>.plus(other: LongSparseArray<T>)
通过添加或替换来自 other 的条目来创建一个新集合。 |
| Unit |
LongSparseArray<T>.putAll(other: LongSparseArray<T>)
通过添加或替换来自 other 的条目来更新此集合。 |
| Boolean |
LongSparseArray<T>.remove(key: Long, value: T)
|
| operator Unit |
LongSparseArray<T>.set(key: Long, value: T)
允许使用索引运算符在集合中存储值。 |
| Iterator<T> |
LongSparseArray<T>.valueIterator()
返回一个遍历集合值的迭代器。 |
针对 android.util.Pair
| operator F |
Pair<F, S>.component1()
返回该对的第一个组件。 |
| operator S |
Pair<F, S>.component2()
返回该对的第二个组件。 |
| Pair<F, S> |
Pair<F, S>.toKotlinPair()
将此 Pair 作为 kotlin.Pair 返回。 |
针对 android.util.Range
| infix Range<T> |
Range<T>.and(other: Range<T>)
返回此范围与 other 的交集。 |
| operator Range<T> |
Range<T>.plus(value: T)
返回包含此范围和 value 的最小范围。 |
| operator Range<T> |
Range<T>.plus(other: Range<T>)
返回包含此范围和 other 的最小范围。 |
| ClosedRange<T> |
Range<T>.toClosedRange()
将此 Range 作为 ClosedRange 返回。 |
针对 android.util.Size
| operator Int |
Size.component1()
返回“宽度”,即此 Size 的第一个组件。 |
| operator Int |
Size.component2()
返回“高度”,即此 Size 的第二个组件。 |
针对 android.util.SizeF
| operator Float |
SizeF.component1()
返回“宽度”,即此 SizeF 的第一个组件。 |
| operator Float |
SizeF.component2()
返回“高度”,即此 SizeF 的第二个组件。 |
针对 android.util.SparseArray
| operator Boolean |
SparseArray<T>.contains(key: Int)
如果集合包含 key,则返回 true。 |
| Boolean |
SparseArray<T>.containsKey(key: Int)
如果集合包含 key,则返回 true。 |
| Boolean |
SparseArray<T>.containsValue(value: T)
如果集合包含 value,则返回 true。 |
| Unit |
SparseArray<T>.forEach(action: (key: Int, value: T) -> Unit)
对每个键/值条目执行给定的 action。 |
| T |
SparseArray<T>.getOrDefault(key: Int, defaultValue: T)
返回对应于 key 的值,如果不存在,则返回 defaultValue。 |
| T |
SparseArray<T>.getOrElse(key: Int, defaultValue: () -> T)
返回对应于 key 的值,如果不存在,则返回 defaultValue 的计算结果。 |
| Boolean |
SparseArray<T>.isEmpty()
当集合不包含任何元素时返回 true。 |
| Boolean |
SparseArray<T>.isNotEmpty()
当集合包含元素时返回 true。 |
| IntIterator |
SparseArray<T>.keyIterator()
返回一个遍历集合键的迭代器。 |
| operator SparseArray<T> |
SparseArray<T>.plus(other: SparseArray<T>)
通过添加或替换来自 other 的条目来创建一个新集合。 |
| Unit |
SparseArray<T>.putAll(other: SparseArray<T>)
通过添加或替换来自 other 的条目来更新此集合。 |
| Boolean |
SparseArray<T>.remove(key: Int, value: T)
|
| operator Unit |
SparseArray<T>.set(key: Int, value: T)
允许使用索引运算符在集合中存储值。 |
| Iterator<T> |
SparseArray<T>.valueIterator()
返回一个遍历集合值的迭代器。 |
针对 android.util.SparseBooleanArray
针对 android.util.SparseIntArray
针对 android.util.SparseLongArray
针对 kotlin.Double
| Half |
Double.toHalf()
|
针对 kotlin.Float
| Half |
Float.toHalf()
|
针对 kotlin.Pair
| Pair<F, S> |
Pair<F, S>.toAndroidPair()
将此 kotlin.Pair 作为 Android Pair 返回。 |
针对 kotlin.Short
| Half |
Short.toHalf()
|
针对 kotlin.String
| Half |
String.toHalf()
|
针对 kotlin.ranges.ClosedRange
| Range<T> |
ClosedRange<T>.toRange()
将此 ClosedRange 作为 Range 返回。 |
扩展属性
针对 android.util.LongSparseArray
| Int |
LongSparseArray<T>.size()
返回集合中键值对的数量。 |
针对 android.util.SparseArray
| Int |
SparseArray<T>.size()
返回集合中键值对的数量。 |
针对 android.util.SparseBooleanArray
| Int |
SparseBooleanArray.size()
返回集合中键值对的数量。 |
针对 android.util.SparseIntArray
| Int |
SparseIntArray.size()
返回集合中键值对的数量。 |
针对 android.util.SparseLongArray
| Int |
SparseLongArray.size()
返回集合中键值对的数量。 |
顶层函数
| LruCache<K, V> |
lruCache(maxSize: Int, crossinline sizeOf: (key: K, value: V) -> Int = { _, _ -> 1 }, crossinline create: (key: K) -> V? = { null as V? }, crossinline onEntryRemoved: (evicted: Boolean, key: K, oldValue: V, newValue: V?) -> Unit = { _, _, _, _ -> })
使用给定的参数创建一个 LruCache。 |
| infix Range<T> |
T.rangeTo(that: T)
创建一个从当前 Comparable 值到 that 的范围。 |
androidx.core.view
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.19.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.19.0") }
扩展函数
针对 android.view.Menu
| operator Boolean |
Menu.contains(item: MenuItem)
如果在此菜单中找到 item,则返回 |
| Unit |
Menu.forEach(action: (item: MenuItem) -> Unit)
对该菜单中的每一项执行给定的操作。 |
| Unit |
Menu.forEachIndexed(action: (index: Int, item: MenuItem) -> Unit)
对该菜单中的每一项执行给定的操作,并提供其顺序索引。 |
| operator MenuItem |
Menu.get(index: Int)
返回位于 index 的菜单项。 |
| Boolean |
Menu.isEmpty()
如果此菜单不包含任何项,则返回 true。 |
| Boolean |
Menu.isNotEmpty()
如果此菜单包含一个或多个项,则返回 true。 |
| operator MutableIterator<MenuItem> |
Menu.iterator()
返回一个覆盖此菜单中各项的 MutableIterator。 |
| operator Unit |
Menu.minusAssign(item: MenuItem)
从该菜单中移除 item。 |
针对 android.view.View
| Unit |
View.doOnAttach(crossinline action: (view: View) -> Unit)
当此视图附加到窗口时,执行给定的操作。 |
| Unit |
View.doOnDetach(crossinline action: (view: View) -> Unit)
当此视图从窗口分离时,执行给定的操作。 |
| Unit |
View.doOnLayout(crossinline action: (view: View) -> Unit)
当此视图进行布局时,执行给定的操作。 |
| Unit |
View.doOnNextLayout(crossinline action: (view: View) -> Unit)
当此视图下一次进行布局时,执行给定的操作。 |
| OneShotPreDrawListener |
View.doOnPreDraw(crossinline action: (view: View) -> Unit)
当视图树即将绘制时,执行给定的操作。 |
| Bitmap |
View.drawToBitmap(config: Config = Bitmap.Config.ARGB_8888)
|
| Runnable |
View.postDelayed(delayInMillis: Long, crossinline action: () -> Unit)
View.postDelayed 的版本,它重新排列了参数,允许将操作放在括号外。 |
| Runnable |
View.postOnAnimationDelayed(delayInMillis: Long, crossinline action: () -> Unit)
View.postOnAnimationDelayed 的版本,它重新排列了参数,允许将操作放在括号外。 |
| Unit |
View.setPadding(@Px size: Int)
设置视图的内边距。 |
| Unit |
View.updateLayoutParams(block: LayoutParams.() -> Unit)
使用视图的 layoutParams 执行 block,并使用更新后的版本重新分配 layoutParams。 |
| Unit |
View.updateLayoutParams(block: T.() -> Unit)
使用视图的 layoutParams 的类型化版本执行 block,并使用更新后的版本重新分配 layoutParams。 |
| Unit |
View.updatePadding(@Px left: Int = paddingLeft, @Px top: Int = paddingTop, @Px right: Int = paddingRight, @Px bottom: Int = paddingBottom)
更新此视图的内边距。 |
| Unit |
View.updatePaddingRelative(@Px start: Int = paddingStart, @Px top: Int = paddingTop, @Px end: Int = paddingEnd, @Px bottom: Int = paddingBottom)
更新此视图的相对内边距。 |
针对 android.view.ViewGroup
| operator Boolean |
ViewGroup.contains(view: View)
如果在此视图组中找到 view,则返回 |
| Unit |
ViewGroup.forEach(action: (view: View) -> Unit)
对该视图组中的每个视图执行给定的操作。 |
| Unit |
ViewGroup.forEachIndexed(action: (index: Int, view: View) -> Unit)
对该视图组中的每个视图执行给定的操作,并提供其顺序索引。 |
| operator View |
ViewGroup.get(index: Int)
返回位于 index 的视图。 |
| Boolean |
ViewGroup.isEmpty()
如果此视图组不包含任何视图,则返回 true。 |
| Boolean |
ViewGroup.isNotEmpty()
如果此视图组包含一个或多个视图,则返回 true。 |
| operator MutableIterator<View> |
ViewGroup.iterator()
返回一个覆盖此视图组中视图的 MutableIterator。 |
| operator Unit |
ViewGroup.minusAssign(view: View)
从该视图组中移除 view。 |
| operator Unit |
ViewGroup.plusAssign(view: View)
将 view 添加到该视图组中。 |
针对 android.view.ViewGroup.MarginLayoutParams
| Unit |
MarginLayoutParams.setMargins(@Px size: Int)
在 ViewGroup 的 MarginLayoutParams 中设置外边距。 |
| Unit |
MarginLayoutParams.updateMargins(@Px left: Int = leftMargin, @Px top: Int = topMargin, @Px right: Int = rightMargin, @Px bottom: Int = bottomMargin)
更新 ViewGroup 的 ViewGroup.MarginLayoutParams 中的外边距。 |
| Unit |
MarginLayoutParams.updateMarginsRelative(@Px start: Int = marginStart, @Px top: Int = topMargin, @Px end: Int = marginEnd, @Px bottom: Int = bottomMargin)
更新 ViewGroup 的 MarginLayoutParams 中的相对外边距。 |
扩展属性
针对 android.view.Menu
| Sequence<MenuItem> |
Menu.children()
返回覆盖此菜单中各项的 Sequence。 |
| Int |
Menu.size()
返回此菜单中项的数量。 |
针对 android.view.View
| Boolean |
View.isGone()
当此视图的可见性为 View.GONE 时返回 true,否则返回 false。 |
| Boolean |
View.isInvisible()
当此视图的可见性为 View.INVISIBLE 时返回 true,否则返回 false。 |
| Boolean |
View.isVisible()
当此视图的可见性为 View.VISIBLE 时返回 true,否则返回 false。 |
| Int |
View.marginBottom()
如果此视图的 LayoutParams 是 ViewGroup.MarginLayoutParams,则返回底部外边距,否则返回 0。 |
| Int |
View.marginEnd()
如果此视图的 LayoutParams 是 ViewGroup.MarginLayoutParams,则返回结束外边距,否则返回 0。 |
| Int |
View.marginLeft()
如果此视图的 LayoutParams 是 ViewGroup.MarginLayoutParams,则返回左侧外边距,否则返回 0。 |
| Int |
View.marginRight()
如果此视图的 LayoutParams 是 ViewGroup.MarginLayoutParams,则返回右侧外边距,否则返回 0。 |
| Int |
View.marginStart()
如果此视图的 LayoutParams 是 ViewGroup.MarginLayoutParams,则返回起始外边距,否则返回 0。 |
| Int |
View.marginTop()
如果此视图的 LayoutParams 是 ViewGroup.MarginLayoutParams,则返回顶部外边距,否则返回 0。 |
针对 android.view.ViewGroup
| Sequence<View> |
ViewGroup.children()
返回覆盖此视图组中子视图的 Sequence。 |
| Int |
ViewGroup.size()
返回此视图组中视图的数量。 |
androidx.core.widget
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.19.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.19.0") }
扩展函数
针对 android.widget.TextView
| TextWatcher |
TextView.addTextChangedListener(crossinline beforeTextChanged: (text: CharSequence?, start: Int, count: Int, after: Int) -> Unit = { _, _, _, _ -> }, crossinline onTextChanged: (text: CharSequence?, start: Int, count: Int, after: Int) -> Unit = { _, _, _, _ -> }, crossinline afterTextChanged: (text: Editable?) -> Unit = {})
使用提供的操作为此 TextView 添加文本更改监听器。 |
| TextWatcher |
TextView.doAfterTextChanged(crossinline action: (text: Editable?) -> Unit)
添加一个将在文本更改后调用的操作。 |
| TextWatcher |
TextView.doBeforeTextChanged(crossinline action: (text: CharSequence?, start: Int, count: Int, after: Int) -> Unit)
添加一个将在文本更改前调用的操作。 |
| TextWatcher |
TextView.doOnTextChanged(crossinline action: (text: CharSequence?, start: Int, count: Int, after: Int) -> Unit)
添加一个将在文本正在更改时调用的操作。 |
androidx.dynamicanimation.animation
依赖项
Groovy
dependencies { implementation "androidx.dynamicanimation:dynamicanimation-ktx:" }
Kotlin
dependencies { implementation("androidx.dynamicanimation:dynamicanimation-ktx:") }
扩展函数
针对 SpringAnimation
| SpringAnimation |
SpringAnimation.withSpringForceProperties(func: SpringForce.() -> Unit)
更新或应用 SpringAnimation 上的弹簧力属性,例如 SpringForce.mDampingRatio、SpringForce.mFinalPosition 和硬度。 |
顶层函数
| FlingAnimation |
flingAnimationOf(setter: (Float) -> Unit, getter: () -> Float)
为可通过提供的 setter 和 getter 访问的属性创建 FlingAnimation。 |
| SpringAnimation |
springAnimationOf(setter: (Float) -> Unit, getter: () -> Float, finalPosition: Float = Float.NaN)
为可通过提供的 setter 和 getter 访问的属性创建 SpringAnimation。 |
androidx.fragment.app
依赖项
Groovy
dependencies { implementation "androidx.fragment:fragment-ktx:1.8.9" }
Kotlin
dependencies { implementation("androidx.fragment:fragment-ktx:1.8.9") }
扩展函数
针对 android.view.View
| F |
View.findFragment()
|
针对 Fragment
| Lazy<VM> |
Fragment.activityViewModels(noinline factoryProducer: () -> ViewModelProvider.Factory = null)
返回一个属性委托,用于访问父 Activity 的 ViewModel;如果指定了 factoryProducer,则它返回的 ViewModelProvider.Factory 将用于首次创建 ViewModel。 |
| Lazy<VM> |
Fragment.createViewModelLazy(viewModelClass: KClass<VM>, storeProducer: () -> ViewModelStore, factoryProducer: () -> ViewModelProvider.Factory = null)
用于创建 ViewModelLazy 的辅助方法,它将作为 factoryProducer 传递的 |
| Lazy<VM> |
Fragment.viewModels(noinline ownerProducer: () -> ViewModelStoreOwner = { this }, noinline factoryProducer: () -> ViewModelProvider.Factory = null)
|
针对 FragmentTransaction
| FragmentTransaction |
FragmentTransaction.add(@IdRes containerViewId: Int, tag: String? = null, args: Bundle? = null)
向关联的 FragmentManager 添加一个 Fragment,将 Fragment 的视图加载到由 containerViewId 指定的容器视图中,以便稍后通过 FragmentManager.findFragmentById 检索。 |
| FragmentTransaction |
FragmentTransaction.add(tag: String, args: Bundle? = null)
向关联的 FragmentManager 添加一个 Fragment,而不将该 Fragment 添加到任何容器视图中。 |
| FragmentTransaction |
FragmentTransaction.replace(@IdRes containerViewId: Int, tag: String? = null, args: Bundle? = null)
替换已添加到容器中的现有 Fragment。 |
针对 FragmentManager
| Unit |
FragmentManager.commit(allowStateLoss: Boolean = false, body: FragmentTransaction.() -> Unit)
在 FragmentTransaction 中运行 body,如果该事务在没有异常的情况下完成,它将自动提交。 |
| Unit |
FragmentManager.commitNow(allowStateLoss: Boolean = false, body: FragmentTransaction.() -> Unit)
在 FragmentTransaction 中运行 body,如果该事务在没有异常的情况下完成,它将自动提交。 |
| Unit |
FragmentManager.transaction(now: Boolean = false, allowStateLoss: Boolean = false, body: FragmentTransaction.() -> Unit)
在 FragmentTransaction 中运行 body,如果该事务在没有异常的情况下完成,它将自动提交。 |
androidx.fragment.app.testing
依赖项
Groovy
dependencies { implementation "androidx.fragment:fragment-testing:1.8.9" }
Kotlin
dependencies { implementation("androidx.fragment:fragment-testing:1.8.9") }
顶层函数
| FragmentScenario<F!> |
launchFragment(fragmentArgs: Bundle? = null, @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, factory: FragmentFactory? = null)
启动一个由空 FragmentActivity 托管并使用给定 FragmentFactory 的 Fragment(带有给定参数),并等待它达到 resumed 状态。 |
| FragmentScenario<F!> |
launchFragment(fragmentArgs: Bundle? = null, @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, crossinline instantiate: () -> F)
启动一个由空 FragmentActivity 托管的 Fragment(带有给定参数),并使用 instantiate 创建该 Fragment,然后等待它达到 resumed 状态。 |
| FragmentScenario<F!> |
launchFragmentInContainer(fragmentArgs: Bundle? = null, @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, factory: FragmentFactory? = null)
在 Activity 的根视图容器 |
| FragmentScenario<F!> |
launchFragmentInContainer(fragmentArgs: Bundle? = null, @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, crossinline instantiate: () -> F)
在 Activity 的根视图容器 |
androidx.lifecycle
依赖项
Groovy
dependencies { implementation "androidx.lifecycle:lifecycle-livedata-core-ktx:2.11.0" implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.11.0" implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:2.11.0" implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.11.0" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.11.0" }
Kotlin
dependencies { implementation("androidx.lifecycle:lifecycle-livedata-core-ktx:2.11.0") implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.11.0") implementation("androidx.lifecycle:lifecycle-reactivestreams-ktx:2.11.0") implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.11.0") implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.11.0") }
扩展函数
针对 kotlinx.coroutines.flow.Flow
| LiveData<T> |
Flow<T>.asLiveData(context: CoroutineContext = EmptyCoroutineContext, timeoutInMs: Long = DEFAULT_TIMEOUT)
创建一个收集自原始 Flow 的值的 LiveData。 |
| LiveData<T> |
Flow<T>.asLiveData(context: CoroutineContext = EmptyCoroutineContext, timeout: Duration)
创建一个收集自原始 Flow 的值的 LiveData。 |
针对 org.reactivestreams.Publisher
| LiveData<T> |
Publisher<T>.toLiveData()
|
针对 LiveData
| Flow<T> |
LiveData<T>.asFlow()
创建一个包含原始 LiveData 所分发值的 Flow:在开始时,流收集器会接收 LiveData 持有的最新值,然后观察 LiveData 的更新。 |
| LiveData<X> |
LiveData<X>.distinctUntilChanged()
创建一个新的 LiveData 对象,除非原始 |
| LiveData<Y> |
LiveData<X>.map(crossinline transform: (X) -> Y)
返回一个 LiveData,它通过对 |
| Observer<T> |
LiveData<T>.observe(owner: LifecycleOwner, crossinline onChanged: (T) -> Unit)
|
| LiveData<Y> |
LiveData<X>.switchMap(crossinline transform: (X) -> LiveData<Y>)
返回一个 LiveData,它通过对 |
| Publisher<T> |
LiveData<T>.toPublisher(lifecycle: LifecycleOwner)
|
用于 ViewModelProvider
| VM |
ViewModelProvider.get()
返回一个现有的 ViewModel,或在该范围内(通常为 Fragment 或 Activity)创建一个与此 |
用于 LifecycleOwner
| suspend T |
LifecycleOwner.whenCreated(block: suspend CoroutineScope.() -> T)
在 LifecycleOwner 的 Lifecycle 至少处于 Lifecycle.State.CREATED 状态时运行给定的代码块。 |
| suspend T |
LifecycleOwner.whenResumed(block: suspend CoroutineScope.() -> T)
在 LifecycleOwner 的 Lifecycle 至少处于 Lifecycle.State.RESUMED 状态时运行给定的代码块。 |
| suspend T |
LifecycleOwner.whenStarted(block: suspend CoroutineScope.() -> T)
在 LifecycleOwner 的 Lifecycle 至少处于 Lifecycle.State.STARTED 状态时运行给定的代码块。 |
用于 Lifecycle
| suspend T |
Lifecycle.whenCreated(block: suspend CoroutineScope.() -> T)
在 Lifecycle 至少处于 Lifecycle.State.CREATED 状态时运行给定的代码块。 |
| suspend T |
Lifecycle.whenResumed(block: suspend CoroutineScope.() -> T)
在 Lifecycle 至少处于 Lifecycle.State.RESUMED 状态时运行给定的代码块。 |
| suspend T |
Lifecycle.whenStarted(block: suspend CoroutineScope.() -> T)
在 Lifecycle 至少处于 Lifecycle.State.STARTED 状态时运行给定的代码块。 |
| suspend T |
Lifecycle.whenStateAtLeast(minState: Lifecycle.State, block: suspend CoroutineScope.() -> T)
在 CoroutineDispatcher 上运行给定的 block,该分发器会在主线程上执行该 block,并挂起执行,除非 Lifecycle 的状态至少为 minState。 |
扩展属性
用于 Lifecycle
| LifecycleCoroutineScope |
Lifecycle.coroutineScope()
绑定到此 Lifecycle 的 CoroutineScope。 |
用于 LifecycleOwner
| LifecycleCoroutineScope |
LifecycleOwner.lifecycleScope()
绑定到此 LifecycleOwner 的 Lifecycle 的 CoroutineScope。 |
用于 ViewModel
| CoroutineScope |
ViewModel.viewModelScope()
绑定到此 ViewModel 的 CoroutineScope。 |
顶层函数
| LiveData<T> |
liveData(context: CoroutineContext = EmptyCoroutineContext, timeoutInMs: Long = DEFAULT_TIMEOUT, block: suspend LiveDataScope<T>.() -> Unit)
构建一个 LiveData,其值由在 LiveDataScope 上执行的给定 block 产生。 |
| LiveData<T> |
liveData(context: CoroutineContext = EmptyCoroutineContext, timeout: Duration, block: suspend LiveDataScope<T>.() -> Unit)
构建一个 LiveData,其值由在 LiveDataScope 上执行的给定 block 产生。 |
androidx.navigation
依赖项
Groovy
dependencies { implementation "androidx.navigation:navigation-runtime-ktx:2.9.8" implementation "androidx.navigation:navigation-fragment-ktx:2.9.8" implementation "androidx.navigation:navigation-ui-ktx:2.9.8" }
Kotlin
dependencies { implementation("androidx.navigation:navigation-runtime-ktx:2.9.8") implementation("androidx.navigation:navigation-fragment-ktx:2.9.8") implementation("androidx.navigation:navigation-ui-ktx:2.9.8") }
扩展函数
用于 android.app.Activity
| NavController |
Activity.findNavController(@IdRes : Int)
根据 View 的 ID 及其包含的 Activity 查找 NavController。 |
| NavArgsLazy<Args> |
Activity.navArgs()
返回一个 Lazy 委托,以 Args 实例的形式访问 Activity 的 extras。 |
针对 android.view.View
| NavController |
View.findNavController()
查找与 View 相关联的 NavController。 |
用于 NavGraphBuilder
| Unit |
NavGraphBuilder.activity(@IdRes : Int, : ActivityNavigatorDestinationBuilder.() -> Unit)
|
| Unit |
NavGraphBuilder.navigation(@IdRes : Int, @IdRes : Int, : NavGraphBuilder.() -> Unit)
构建一个嵌套的 NavGraph |
用于 NavGraph
| operator Boolean |
NavGraph.contains(@IdRes : Int)
如果在此导航图中找到具有 |
| operator NavDestination |
NavGraph.get(@IdRes : Int)
返回具有 |
| operator Unit |
NavGraph.minusAssign(: NavDestination)
从该导航图中移除 |
| operator Unit |
NavGraph.plusAssign(: NavDestination)
向此 NavGraph 添加一个目标。 |
| operator Unit |
NavGraph.plusAssign(: NavGraph)
将来自另一个集合的所有目标添加到此集合中。 |
用于 NavController
| NavGraph |
NavController.createGraph(@IdRes : Int = 0, @IdRes : Int, : NavGraphBuilder.() -> Unit)
构建一个新的 NavGraph |
用于 NavHost
| NavGraph |
NavHost.createGraph(@IdRes : Int = 0, @IdRes : Int, : NavGraphBuilder.() -> Unit)
构建一个新的 NavGraph |
用于 NavigatorProvider
| operator T |
NavigatorProvider.get(: String)
按名称检索已注册的 Navigator。 |
| operator T |
NavigatorProvider.get(: KClass<T>)
使用 Navigator.Name 注解提供的名称检索已注册的 Navigator。 |
| NavGraph |
NavigatorProvider.navigation(@IdRes : Int = 0, @IdRes : Int, : NavGraphBuilder.() -> Unit)
构建一个新的 NavGraph |
| operator Unit |
NavigatorProvider.plusAssign(: Navigator<out NavDestination>)
使用 Navigator.Name 注解提供的名称注册一个导航器。 |
| operator Navigator<out NavDestination!>? |
NavigatorProvider.set(: String, : Navigator<out NavDestination>)
按名称注册一个 Navigator。 |
针对 Fragment
| Lazy<VM> |
Fragment.navGraphViewModels(: Int, noinline : () -> ViewModelProvider.Factory = null)
返回一个属性委托,以访问作用域为 {@link NavController} 返回栈上存在的导航图的 ViewModel。 |
顶层函数
| ActivityNavigator.Extras |
ActivityNavigatorExtras(: ActivityOptionsCompat? = null, : Int = 0)
使用特定的 ActivityOptionsCompat 实例和/或任何 |
| NavOptions |
navOptions(: NavOptionsBuilder.() -> Unit)
构建一个新的 NavOptions |
androidx.navigation.fragment
依赖项
Groovy
dependencies { implementation "androidx.navigation:navigation-fragment-ktx:2.9.8" }
Kotlin
dependencies { implementation("androidx.navigation:navigation-fragment-ktx:2.9.8") }
扩展函数
用于 NavGraphBuilder
针对 Fragment
| NavController |
Fragment.findNavController()
根据 Fragment 查找 NavController |
| NavArgsLazy<Args> |
Fragment.navArgs()
返回一个 Lazy 委托,以 Args 实例的形式访问 Fragment 的参数。 |
顶层函数
| FragmentNavigator.Extras |
FragmentNavigatorExtras(vararg : Pair<View, String>)
使用给定的共享元素创建一个新的 FragmentNavigator.Extras 实例 |
androidx.navigation.ui
依赖项
Groovy
dependencies { implementation "androidx.navigation:navigation-ui-ktx:2.9.8" }
Kotlin
dependencies { implementation("androidx.navigation:navigation-ui-ktx:2.9.8") }
扩展函数
用于 android.view.MenuItem
| Boolean |
MenuItem.onNavDestinationSelected(: NavController)
尝试导航到与此 MenuItem 相关联的 NavDestination。 |
用于 androidx.appcompat.app.AppCompatActivity
| Unit |
AppCompatActivity.setupActionBarWithNavController(: NavController, : DrawerLayout?)
设置 AppCompatActivity.getSupportActionBar 返回的 ActionBar 以便与 NavController 一起使用。 |
| Unit |
AppCompatActivity.setupActionBarWithNavController(: NavController, : AppBarConfiguration = AppBarConfiguration(navController.graph))
设置 AppCompatActivity.getSupportActionBar 返回的 ActionBar 以便与 NavController 一起使用。 |
用于 androidx.appcompat.widget.Toolbar
| Unit |
Toolbar.setupWithNavController(: NavController, : DrawerLayout?)
设置 Toolbar 以便与 NavController 一起使用。 |
| Unit |
Toolbar.setupWithNavController(: NavController, : AppBarConfiguration = AppBarConfiguration(navController.graph))
设置 Toolbar 以便与 NavController 一起使用。 |
用于 com.google.android.material.appbar.CollapsingToolbarLayout
| Unit |
CollapsingToolbarLayout.setupWithNavController(: Toolbar, : NavController, : DrawerLayout?)
设置 CollapsingToolbarLayout 和 Toolbar 以便与 NavController 一起使用。 |
| Unit |
CollapsingToolbarLayout.setupWithNavController(: Toolbar, : NavController, : AppBarConfiguration = AppBarConfiguration(navController.graph))
设置 CollapsingToolbarLayout 和 Toolbar 以便与 NavController 一起使用。 |
用于 com.google.android.material.bottomnavigation.BottomNavigationView
| Unit |
BottomNavigationView.setupWithNavController(: NavController)
设置 BottomNavigationView 以便与 NavController 一起使用。 |
用于 com.google.android.material.navigation.NavigationView
| Unit |
NavigationView.setupWithNavController(: NavController)
设置 NavigationView 以便与 NavController 一起使用。 |
用于 NavController
| Boolean |
NavController.navigateUp(: DrawerLayout?)
通过将 Up 按钮的行为委托给给定的 NavController 来处理它。 |
| Boolean |
NavController.navigateUp(: AppBarConfiguration)
通过将 Up 按钮的行为委托给给定的 NavController 来处理它。 |
顶层函数
| AppBarConfiguration |
AppBarConfiguration(: NavGraph, : DrawerLayout? = null, noinline : () -> Boolean = { false })
用于 NavigationUI 方法的配置选项,这些方法与应用栏模式的实现交互,例如 android.support.v7.widget.Toolbar、android.support.design.widget.CollapsingToolbarLayout 和 android.support.v7.app.ActionBar。 |
| AppBarConfiguration |
AppBarConfiguration(: Menu, : DrawerLayout? = null, noinline : () -> Boolean = { false })
用于 NavigationUI 方法的配置选项,这些方法与应用栏模式的实现交互,例如 android.support.v7.widget.Toolbar、android.support.design.widget.CollapsingToolbarLayout 和 android.support.v7.app.ActionBar。 |
| AppBarConfiguration |
AppBarConfiguration(: Set<Int>, : DrawerLayout? = null, noinline : () -> Boolean = { false })
用于 NavigationUI 方法的配置选项,这些方法与应用栏模式的实现交互,例如 android.support.v7.widget.Toolbar、android.support.design.widget.CollapsingToolbarLayout 和 android.support.v7.app.ActionBar。 |
androidx.paging
依赖项
Groovy
dependencies { implementation "androidx.paging:paging-common-ktx:2.1.2" implementation "androidx.paging:paging-runtime-ktx:2.1.2" implementation "androidx.paging:paging-rxjava2-ktx:2.1.2" }
Kotlin
dependencies { implementation("androidx.paging:paging-common-ktx:2.1.2") implementation("androidx.paging:paging-runtime-ktx:2.1.2") implementation("androidx.paging:paging-rxjava2-ktx:2.1.2") }
扩展函数
用于 Factory
| Flowable<PagedList<Value>> |
DataSource.Factory<Key, Value>.toFlowable(config: PagedList.Config, initialLoadKey: Key? = null, boundaryCallback: PagedList.BoundaryCallback<Value>? = null, fetchScheduler: Scheduler? = null, notifyScheduler: Scheduler? = null, backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST)
构建一个 |
| Flowable<PagedList<Value>> |
DataSource.Factory<Key, Value>.toFlowable(pageSize: Int, initialLoadKey: Key? = null, boundaryCallback: PagedList.BoundaryCallback<Value>? = null, fetchScheduler: Scheduler? = null, notifyScheduler: Scheduler? = null, backpressureStrategy: BackpressureStrategy = BackpressureStrategy.LATEST)
构建一个 |
| LiveData<PagedList<Value>> |
DataSource.Factory<Key, Value>.toLiveData(config: PagedList.Config, initialLoadKey: Key? = null, boundaryCallback: PagedList.BoundaryCallback<Value>? = null, fetchExecutor: Executor = ArchTaskExecutor.getIOThreadExecutor())
构建一个 |
| LiveData<PagedList<Value>> |
DataSource.Factory<Key, Value>.toLiveData(pageSize: Int, initialLoadKey: Key? = null, boundaryCallback: PagedList.BoundaryCallback<Value>? = null, fetchExecutor: Executor = ArchTaskExecutor.getIOThreadExecutor())
构建一个 |
| Observable<PagedList<Value>> |
DataSource.Factory<Key, Value>.toObservable(config: PagedList.Config, initialLoadKey: Key? = null, boundaryCallback: PagedList.BoundaryCallback<Value>? = null, fetchScheduler: Scheduler? = null, notifyScheduler: Scheduler? = null)
构建一个 |
| Observable<PagedList<Value>> |
DataSource.Factory<Key, Value>.toObservable(pageSize: Int, initialLoadKey: Key? = null, boundaryCallback: PagedList.BoundaryCallback<Value>? = null, fetchScheduler: Scheduler? = null, notifyScheduler: Scheduler? = null)
构建一个 |
顶层函数
| PagedList.Config |
Config(pageSize: Int, prefetchDistance: Int = pageSize, enablePlaceholders: Boolean = true, initialLoadSizeHint: Int = pageSize * PagedList.Config.Builder.DEFAULT_INITIAL_PAGE_MULTIPLIER, maxSize: Int = PagedList.Config.MAX_SIZE_UNBOUNDED)
构建一个 PagedList.Config,用于简化 PagedList.Config.Builder 的使用。 |
| PagedList<Value> |
PagedList(dataSource: DataSource<Key, Value>, config: PagedList.Config, notifyExecutor: Executor, fetchExecutor: Executor, boundaryCallback: PagedList.BoundaryCallback<Value>? = null, initialKey: Key? = null)
构建一个 PagedList,用于简化 PagedList.Builder 的使用。 |
androidx.palette.graphics
依赖项
Groovy
dependencies { implementation "androidx.palette:palette-ktx:1.0.0" }
Kotlin
dependencies { implementation("androidx.palette:palette-ktx:1.0.0") }
扩展函数
针对 Palette
| operator Palette.Swatch? |
Palette.get(target: Target)
从调色板中返回给定目标对应的所选样本;如果未找到,则返回 |
androidx.preference
依赖项
Groovy
dependencies { implementation "androidx.preference:preference-ktx:1.2.1" }
Kotlin
dependencies { implementation("androidx.preference:preference-ktx:1.2.1") }
扩展函数
针对 PreferenceGroup
| operator Boolean |
PreferenceGroup.contains(preference: Preference)
如果在此首选项组中找到 |
| Unit |
PreferenceGroup.forEach(action: (preference: Preference) -> Unit)
对该首选项组中的每个首选项执行给定操作。 |
| Unit |
PreferenceGroup.forEachIndexed(action: (index: Int, preference: Preference) -> Unit)
对该首选项组中的每个首选项执行给定操作,并提供其顺序索引。 |
| operator T? |
PreferenceGroup.get(key: CharSequence)
返回带有 |
| operator Preference |
PreferenceGroup.get(index: Int)
返回位于 |
| Boolean |
PreferenceGroup.isEmpty()
如果此首选项组不包含任何首选项,则返回 true。 |
| Boolean |
PreferenceGroup.isNotEmpty()
如果此首选项组包含一个或多个首选项,则返回 true。 |
| operator MutableIterator<Preference> |
PreferenceGroup.iterator()
返回遍历该首选项组中首选项的 MutableIterator。 |
| operator Unit |
PreferenceGroup.minusAssign(preference: Preference)
从该首选项组中移除 |
| operator Unit |
PreferenceGroup.plusAssign(preference: Preference)
将 |
扩展属性
针对 PreferenceGroup
| Sequence<Preference> |
PreferenceGroup.children()
返回遍历该首选项组中首选项的 Sequence。 |
| Int |
PreferenceGroup.size()
返回该首选项组中的首选项数量。 |
androidx.room
依赖项
Groovy
dependencies { implementation "androidx.room:room-ktx:2.8.4" }
Kotlin
dependencies { implementation("androidx.room:room-ktx:2.8.4") }
扩展函数
针对 RoomDatabase
| suspend R |
RoomDatabase.withTransaction(block: suspend () -> R)
在数据库事务中调用指定的挂起 block。 |
androidx.slice.builders
依赖项
Groovy
dependencies { implementation "androidx.slice:slice-builders-ktx:1.0.0-alpha08" }
Kotlin
dependencies { implementation("androidx.slice:slice-builders-ktx:1.0.0-alpha08") }
扩展函数
针对 GridRowBuilderDsl
| GridRowBuilder |
GridRowBuilderDsl.cell(buildCell: CellBuilderDsl.() -> Unit)
|
| GridRowBuilder |
GridRowBuilderDsl.seeMoreCell(buildCell: CellBuilderDsl.() -> Unit)
|
针对 ListBuilderDsl
| ListBuilder |
ListBuilderDsl.gridRow(buildGrid: GridRowBuilderDsl.() -> Unit)
|
| ListBuilder |
ListBuilderDsl.header(buildHeader: HeaderBuilderDsl.() -> Unit)
|
| ListBuilder |
ListBuilderDsl.inputRange(buildInputRange: InputRangeBuilderDsl.() -> Unit)
|
| ListBuilder |
ListBuilderDsl.range(buildRange: RangeBuilderDsl.() -> Unit)
|
| ListBuilder |
ListBuilderDsl.row(buildRow: RowBuilderDsl.() -> Unit)
|
| ListBuilder |
ListBuilderDsl.seeMoreRow(buildRow: RowBuilderDsl.() -> Unit)
|
顶层函数
| Slice |
list(context: Context, uri: Uri, ttl: Long, addRows: ListBuilderDsl.() -> Unit)
减少在 Kotlin 中构建 Slice 所需的冗余代码。 |
| SliceAction |
tapSliceAction(pendingIntent: PendingIntent, icon: IconCompat, imageMode: Int = ICON_IMAGE, title: CharSequence)
用于构建可点击 SliceAction 的工厂方法。 |
| SliceAction |
toggleSliceAction(pendingIntent: PendingIntent, icon: IconCompat? = null, title: CharSequence, isChecked: Boolean)
用于构建可切换 SliceAction 的工厂方法。 |
androidx.sqlite.db
依赖项
Groovy
dependencies { implementation "androidx.sqlite:sqlite-ktx:2.6.2" }
Kotlin
dependencies { implementation("androidx.sqlite:sqlite-ktx:2.6.2") }
扩展函数
针对 SupportSQLiteDatabase
| T |
SupportSQLiteDatabase.transaction(exclusive: Boolean = true, body: SupportSQLiteDatabase.() -> T)
在一个事务中运行 body,如果执行过程未抛出异常,则将该事务标记为成功。 |
androidx.work
依赖项
扩展函数
针对 com.google.common.util.concurrent.ListenableFuture
| suspend R |
ListenableFuture<R>.await()
等待 ListenableFuture 完成,且不阻塞线程。 |
针对 Operation
| suspend Operation.State.SUCCESS! |
Operation.await()
等待 Operation 完成,且不阻塞线程。 |
针对 Data
| Boolean |
Data.hasKeyWithValueOfType(key: String)
|
针对 Builder
| OneTimeWorkRequest.Builder |
OneTimeWorkRequest.Builder.setInputMerger(@NonNull inputMerger: KClass<out InputMerger>)
|
顶层函数
| OneTimeWorkRequest.Builder |
OneTimeWorkRequestBuilder()
创建一个具有给定 ListenableWorker 的 OneTimeWorkRequest。 |
| PeriodicWorkRequest.Builder |
PeriodicWorkRequestBuilder(repeatInterval: Long, repeatIntervalTimeUnit: TimeUnit)
创建一个具有给定 ListenableWorker 的 PeriodicWorkRequest.Builder。 |
| PeriodicWorkRequest.Builder |
PeriodicWorkRequestBuilder(repeatInterval: Duration)
创建一个具有给定 ListenableWorker 的 PeriodicWorkRequest.Builder。 |
| PeriodicWorkRequest.Builder |
PeriodicWorkRequestBuilder(repeatInterval: Long, repeatIntervalTimeUnit: TimeUnit, flexTimeInterval: Long, flexTimeIntervalUnit: TimeUnit)
创建一个具有给定 ListenableWorker 的 PeriodicWorkRequest.Builder。 |
| PeriodicWorkRequest.Builder |
PeriodicWorkRequestBuilder(repeatInterval: Duration, flexTimeInterval: Duration)
创建一个具有给定 ListenableWorker 的 PeriodicWorkRequest.Builder。 |
| Data |
workDataOf(vararg pairs: Pair<String, Any?>)
将键值对列表转换为 Data 对象。 |
androidx.work.testing
依赖项
Groovy
dependencies { implementation "androidx.work:work-testing:2.11.2" }
Kotlin
dependencies { implementation("androidx.work:work-testing:2.11.2") }
顶层函数
| TestListenableWorkerBuilder<W> |
TestListenableWorkerBuilder(context: Context, inputData: Data = Data.EMPTY, tags: List<String> = emptyList(), runAttemptCount: Int = 1, triggeredContentUris: List<Uri> = emptyList(), triggeredContentAuthorities: List<String> = emptyList())
构建 TestListenableWorkerBuilder 的一个实例。 |
| TestWorkerBuilder<W> |
TestWorkerBuilder(context: Context, executor: Executor, inputData: Data = Data.EMPTY, tags: List<String> = emptyList(), runAttemptCount: Int = 1, triggeredContentUris: List<Uri> = emptyList(), triggeredContentAuthorities: List<String> = emptyList())
构建 TestWorkerBuilder 的一个实例。 |
com.google.android.play.core.ktx
依赖项
Groovy
dependencies { implementation "com.google.android.play:core-ktx:1.8.1" }
Kotlin
dependencies { implementation("com.google.android.play:core-ktx:1.8.1") }
扩展函数
针对 com.google.android.play.core.appupdate.AppUpdateManager
| suspend AppUpdateInfo |
AppUpdateManager.requestAppUpdateInfo()
请求当前应用的更新可用性。 |
| suspend Unit |
AppUpdateManager.requestCompleteUpdate()
对于灵活的更新流程,触发更新完成。 |
| Flow<AppUpdateResult> |
AppUpdateManager.requestUpdateFlow()
用于监控更新可用性和进度的入口点。 |
| Boolean |
AppUpdateManager.startUpdateFlowForResult(appUpdateInfo: AppUpdateInfo, appUpdateType: Int, fragment: Fragment, requestCode: Int)
AppUpdateManager.startUpdateFlowForResult 的一个版本,它接受一个 AndroidX Fragment 以返回结果。 |
针对 com.google.android.play.core.splitinstall.SplitInstallManager
扩展属性
针对 com.google.android.play.core.appupdate.AppUpdateInfo
| Int |
AppUpdateInfo.installStatus()
返回更新的进度状态。 |
| Boolean |
AppUpdateInfo.isFlexibleUpdateAllowed()
如果允许灵活更新,则返回 |
| Boolean |
AppUpdateInfo.isImmediateUpdateAllowed()
如果允许立即更新,则返回 |
针对 com.google.android.play.core.install.InstallState
| Boolean |
InstallState.hasTerminalStatus()
这表示这是一个终端状态(将不会有更多更新),应进行相应处理(成功、取消或失败)。 |
| Int |
InstallState.installErrorCode()
返回安装错误代码,或 {@link InstallErrorCode#NO_ERROR}。 |
| Int |
InstallState.installStatus()
返回安装状态。 |
| String! |
InstallState.packageName()
返回正在安装的应用的包名。 |
针对 com.google.android.play.core.splitinstall.SplitInstallSessionState
| Long |
SplitInstallSessionState.bytesDownloaded()
此更新已下载的字节数。 |
| Int |
SplitInstallSessionState.errorCode()
此更新的错误代码。 |
| Boolean |
SplitInstallSessionState.hasTerminalStatus()
表示此更新是终端状态,意味着此会话将不会有更多更新。 |
| List<String> |
SplitInstallSessionState.languages()
此更新包含的语言。 |
| List<String> |
SplitInstallSessionState.moduleNames()
此更新包含的模块。 |
| Int |
SplitInstallSessionState.sessionId()
此更新的会话 ID。 |
| Int |
SplitInstallSessionState.status()
此更新的状态代码。 |
| Long |
SplitInstallSessionState.totalBytesToDownload()
此更新需要下载的总字节数。 |
顶层函数
| SplitInstallStateUpdatedListener |
SplitInstallStateUpdatedListener(onRequiresConfirmation: (SplitInstallSessionState) -> Unit, onInstalled: (SplitInstallSessionState) -> Unit, onFailed: (SplitInstallSessionState) -> Unit = {}, onPending: (SplitInstallSessionState) -> Unit = {}, onDownloaded: (SplitInstallSessionState) -> Unit = {}, onDownloading: (SplitInstallSessionState) -> Unit = {}, onInstalling: (SplitInstallSessionState) -> Unit = {}, onCanceling: (SplitInstallSessionState) -> Unit = {}, onCanceled: (SplitInstallSessionState) -> Unit = {}, onNonTerminalStatus: (SplitInstallSessionState) -> Unit = {}, onTerminalStatus: (SplitInstallSessionState) -> Unit = {})
用于创建 SplitInstallStateUpdatedListener 的便利函数。 |