androidx.activity
依赖项
Groovy
dependencies { implementation "androidx.activity:activity-ktx:1.10.1" }
Kotlin
dependencies { implementation("androidx.activity:activity-ktx:1.10.1") }
扩展函数
适用于 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)
返回一个 Lazy 委托,用于访问 ComponentActivity 的 ViewModel,如果指定了 factoryProducer,则其返回的 ViewModelProvider.Factory 将用于首次创建 ViewModel。 |
androidx.benchmark
依赖项
Groovy
dependencies { implementation "androidx.benchmark:benchmark-junit4:1.3.4" }
Kotlin
dependencies { implementation("androidx.benchmark:benchmark-junit4:1.3.4") }
顶级函数
Unit |
beginTraceSection(sectionName: String)
|
Unit |
endTraceSection()
|
androidx.benchmark.junit4
依赖项
Groovy
dependencies { implementation "androidx.benchmark:benchmark-junit4:1.3.4" }
Kotlin
dependencies { implementation("androidx.benchmark:benchmark-junit4:1.3.4") }
扩展函数
适用于 BenchmarkRule
Unit |
BenchmarkRule.measureRepeated(crossinline block: BenchmarkRule.Scope.() -> Unit)
对代码块进行基准测试。 |
androidx.collection
依赖项
Groovy
dependencies { implementation "androidx.collection:collection-ktx:1.5.0" }
Kotlin
dependencies { implementation("androidx.collection:collection-ktx:1.5.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.16.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.16.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.16.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.16.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.16.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.16.0") }
扩展函数
适用于 android.content.res.TypedArray
androidx.core.database
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.16.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.16.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.16.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.16.0") }
扩展函数
适用于 android.database.sqlite.SQLiteDatabase
T |
SQLiteDatabase.transaction(exclusive: Boolean = true, body: SQLiteDatabase.() -> T)
在事务中运行 body,如果 body 在没有异常的情况下完成,则将其标记为成功。 |
androidx.core.graphics
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.16.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.16.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)
从源创建位图。 |
Drawable |
Source.decodeDrawable(crossinline action: ImageDecoder.(info: ImageInfo, source: Source) -> Unit)
从源创建 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 中记录命令,在新创建的 Canvas 上执行指定的 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()
指示颜色是否在 wide-gamut 颜色空间中。 |
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.16.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.16.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)
更新此可绘制对象的边界。 |
针对 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.16.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.16.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.16.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.16.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.16.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.16.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.16.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.16.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()
从 CharSequence 返回一个新的 Spannable,如果它已经是 SpannableString 的实例,则返回其自身。 |
Spanned |
CharSequence.toSpanned()
从 CharSequence 返回一个新的 Spanned,如果它已经是 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.16.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.16.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)
添加一个在此 transition 被取消时将调用的操作。 |
TransitionListener |
Transition.doOnEnd(crossinline action: (transition: Transition) -> Unit)
添加一个在此 transition 结束时将调用的操作。 |
TransitionListener |
Transition.doOnPause(crossinline action: (transition: Transition) -> Unit)
添加一个在此 transition 被暂停时将调用的操作。 |
TransitionListener |
Transition.doOnResume(crossinline action: (transition: Transition) -> Unit)
添加一个在此 transition 暂停后恢复时将调用的操作。 |
TransitionListener |
Transition.doOnStart(crossinline action: (transition: Transition) -> Unit)
添加一个在此 transition 启动时将调用的操作。 |
androidx.core.util
依赖项
Groovy
dependencies { implementation "androidx.core:core-ktx:1.16.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.16.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
针对 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()
返回“width”,即此 Size 的第一个组件。 |
operator Int |
Size.component2()
返回“height”,即此 Size 的第二个组件。 |
针对 android.util.SizeF
operator Float |
SizeF.component1()
返回“width”,即此 SizeF 的第一个组件。 |
operator Float |
SizeF.component2()
返回“height”,即此 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.16.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.16.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)
使用 View 的 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.16.0" }
Kotlin
dependencies { implementation("androidx.core:core-ktx:1.16.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)
更新或应用 SpringForce.mDampingRatio、SpringForce.mFinalPosition 和 stiffness 等弹簧力属性到 SpringAnimation 上。 |
顶级函数
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.8" }
Kotlin
dependencies { implementation("androidx.fragment:fragment-ktx:1.8.8") }
扩展函数
针对 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)
将一个 Fragment 添加到关联的 FragmentManager,将 Fragment 的视图膨胀到由 containerViewId 指定的容器视图中,以便稍后通过 FragmentManager.findFragmentById 进行检索。 |
FragmentTransaction |
FragmentTransaction.add(tag: String, args: Bundle? = null)
将 Fragment 添加到关联的 FragmentManager 中,无需将 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.8" }
Kotlin
dependencies { implementation("androidx.fragment:fragment-testing:1.8.8") }
顶级函数
FragmentScenario<F!> |
launchFragment(fragmentArgs: Bundle? = null, @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, factory: FragmentFactory? = null)
启动一个带有给定参数的 Fragment,该 Fragment 由空的 FragmentActivity 托管,并使用给定的 FragmentFactory,然后等待它达到恢复状态。 |
FragmentScenario<F!> |
launchFragment(fragmentArgs: Bundle? = null, @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, crossinline instantiate: () -> F)
启动一个带有给定参数的 Fragment,该 Fragment 由空的 FragmentActivity 托管,并使用 instantiate 来创建 Fragment,然后等待它达到恢复状态。 |
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.9.1" implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.9.1" implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:2.9.1" implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.9.1" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.9.1" }
Kotlin
dependencies { implementation("androidx.lifecycle:lifecycle-livedata-core-ktx:2.9.1") implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.9.1") implementation("androidx.lifecycle:lifecycle-reactivestreams-ktx:2.9.1") implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.9.1") implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.9.1") }
扩展函数
对于 kotlinx.coroutines.flow.Flow
LiveData<T> |
Flow<T>.asLiveData(context: CoroutineContext = EmptyCoroutineContext, timeoutInMs: Long = DEFAULT_TIMEOUT)
创建一个 LiveData,其值是从原始 Flow 收集而来的。 |
LiveData<T> |
Flow<T>.asLiveData(context: CoroutineContext = EmptyCoroutineContext, timeout: Duration)
创建一个 LiveData,其值是从原始 Flow 收集而来的。 |
对于 org.reactivestreams.Publisher
LiveData<T> |
Publisher<T>.toLiveData()
|
对于 LiveData
Flow<T> |
LiveData<T>.asFlow()
创建一个 Flow,其中包含由原始 LiveData 分发的值:在开始时,流收集器会收到 LiveData 持有的最新值,然后观察 LiveData 更新。 |
LiveData<X> |
LiveData<X>.distinctUntilChanged()
创建一个新的 LiveData 对象,在源 |
LiveData<Y> |
LiveData<X>.map(crossinline transform: (X) -> Y)
返回一个从 |
Observer<T> |
LiveData<T>.observe(owner: LifecycleOwner, crossinline onChanged: (T) -> Unit)
|
LiveData<Y> |
LiveData<X>.switchMap(crossinline transform: (X) -> LiveData<Y>)
返回一个从输入的 |
Publisher<T> |
LiveData<T>.toPublisher(lifecycle: LifecycleOwner)
|
对于 ViewModelProvider
VM |
ViewModelProvider.get()
返回一个现有 ViewModel,或在此 |
对于 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.0" implementation "androidx.navigation:navigation-fragment-ktx:2.9.0" implementation "androidx.navigation:navigation-ui-ktx:2.9.0" }
Kotlin
dependencies { implementation("androidx.navigation:navigation-runtime-ktx:2.9.0") implementation("androidx.navigation:navigation-fragment-ktx:2.9.0") implementation("androidx.navigation:navigation-ui-ktx:2.9.0") }
扩展函数
对于 android.app.Activity
NavController |
Activity.findNavController(@IdRes : Int)
根据 View 的 ID 及其包含的 Activity 查找 NavController。 |
NavArgsLazy<Args> |
Activity.navArgs()
返回一个 Lazy 委托,用于将 Activity 的额外数据作为 Args 实例进行访问。 |
针对 android.view.View
NavController |
View.findNavController()
查找与 View 关联的 NavController。 |
对于 NavGraphBuilder
Unit |
NavGraphBuilder.activity(@IdRes : Int, : ActivityNavigatorDestinationBuilder.() -> Unit)
构造一个新的 ActivityNavigator.Destination。 |
Unit |
NavGraphBuilder.navigation(@IdRes : Int, @IdRes : Int, : NavGraphBuilder.() -> Unit)
构造一个嵌套的 NavGraph。 |
对于 NavGraph
operator Boolean |
NavGraph.contains(@IdRes : Int)
如果在此导航图中找到 ID 为 |
operator NavDestination |
NavGraph.get(@IdRes : Int)
返回 ID 为 |
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 annotation 提供的名称检索已注册的 Navigator。 |
NavGraph |
NavigatorProvider.navigation(@IdRes : Int = 0, @IdRes : Int, : NavGraphBuilder.() -> Unit)
构造一个新的 NavGraph。 |
operator Unit |
NavigatorProvider.plusAssign(: Navigator<out NavDestination>)
使用 Navigator.Name annotation 提供的名称注册一个 navigator。 |
operator Navigator<out NavDestination!>? |
NavigatorProvider.set(: String, : Navigator<out NavDestination>)
按名称注册一个 Navigator。 |
针对 Fragment
Lazy<VM> |
Fragment.navGraphViewModels(@IdRes : Int, noinline : () -> ViewModelProvider.Factory = null)
返回一个属性委托,用于访问作用域限定到 {@link NavController} 返回堆栈上存在的导航图的 ViewModel。 |
顶级函数
ActivityNavigator.Extras |
ActivityNavigatorExtras(: ActivityOptionsCompat? = null, : Int = 0)
创建一个新的 ActivityNavigator.Extras 实例,其中包含特定的 ActivityOptionsCompat 实例和/或任何 |
NavOptions |
navOptions(: NavOptionsBuilder.() -> Unit)
构造一个新的 NavOptions。 |
androidx.navigation.fragment
依赖项
Groovy
dependencies { implementation "androidx.navigation:navigation-fragment-ktx:2.9.0" }
Kotlin
dependencies { implementation("androidx.navigation:navigation-fragment-ktx:2.9.0") }
扩展函数
对于 NavGraphBuilder
Unit |
NavGraphBuilder.dialog(@IdRes : Int)
|
Unit |
NavGraphBuilder.dialog(@IdRes : Int, : DialogFragmentNavigatorDestinationBuilder.() -> Unit)
|
Unit |
NavGraphBuilder.fragment(@IdRes : Int)
构造一个新的 FragmentNavigator.Destination。 |
Unit |
NavGraphBuilder.fragment(@IdRes : Int, : FragmentNavigatorDestinationBuilder.() -> Unit)
构造一个新的 FragmentNavigator.Destination。 |
针对 Fragment
NavController |
Fragment.findNavController()
查找给定 Fragment 的 NavController。 |
NavArgsLazy<Args> |
Fragment.navArgs()
返回一个 Lazy 委托,用于将 Fragment 的参数作为 Args 实例进行访问。 |
顶级函数
FragmentNavigator.Extras |
FragmentNavigatorExtras(vararg : Pair<View, String>)
创建一个新的 FragmentNavigator.Extras 实例,其中包含给定的共享元素。 |
androidx.navigation.ui
依赖项
Groovy
dependencies { implementation "androidx.navigation:navigation-ui-ktx:2.9.0" }
Kotlin
dependencies { implementation("androidx.navigation:navigation-ui-ktx:2.9.0") }
扩展函数
对于 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?)
通过将其行为委托给给定的 NavController 来处理“向上”按钮。 |
Boolean |
NavController.navigateUp(: AppBarConfiguration)
通过将其行为委托给给定的 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.7.1" }
Kotlin
dependencies { implementation("androidx.room:room-ktx:2.7.1") }
扩展函数
适用于 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.5.1" }
Kotlin
dependencies { implementation("androidx.sqlite:sqlite-ktx:2.5.1") }
扩展函数
适用于 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 上设置一个 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.10.1" }
Kotlin
dependencies { implementation("androidx.work:work-testing:2.10.1") }
顶级函数
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)
接受 AndroidX Fragment 以返回结果的 AppUpdateManager.startUpdateFlowForResult 版本。 |
适用于 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 的便捷函数。 |