KTX 擴充功能清單

androidx.activity

依附元件

Groovy

dependencies {
    implementation "androidx.activity:activity-ktx:1.9.0"
}

Kotlin

dependencies {
    implementation("androidx.activity:activity-ktx:1.9.0")
}

擴充功能函式

適用於 OnBack PressedDispatcher
OnBackPressedCallback OnBackPressedDispatcher.addCallback(owner: LifecycleOwner? = null, enabled: Boolean = true, onBackPressed: OnBackPressedCallback.() -> Unit)

建立和新增 OnBackButtonedCallback,藉此呼叫 OnBack PressedCallback.handleOnBack Pressed 中的 onBack Pressed

適用於 ComponentActivity
Lazy<VM> ComponentActivity.viewModels(noinline factoryProducer: () -> ViewModelProvider.Factory = null)

傳回延遲委派,來存取 ComponentActivity 的 ViewModel。如果指定了 factoryProducer,則其傳回的 ViewModelProvider.Factory 會用來首次建立 ViewModel

androidx.benchmark

依附元件

Groovy

dependencies {
    implementation "androidx.benchmark:benchmark-junit4:1.2.1"
}

Kotlin

dependencies {
    implementation("androidx.benchmark:benchmark-junit4:1.2.1")
}

頂層函式

Unit beginTraceSection(sectionName: String)

Unit endTraceSection()

androidx.benchmark.junit4

依附元件

Groovy

dependencies {
    implementation "androidx.benchmark:benchmark-junit4:1.2.1"
}

Kotlin

dependencies {
    implementation("androidx.benchmark:benchmark-junit4:1.2.1")
}

擴充功能函式

適用於 BenchmarkRule
Unit BenchmarkRule.measureRepeated(crossinline block: BenchmarkRule.Scope.() -> Unit)

對程式碼區塊執行基準測試。

androidx.collection

依附元件

Groovy

dependencies {
    implementation "androidx.collection:collection-ktx:1.3.0"
}

Kotlin

dependencies {
    implementation("androidx.collection:collection-ktx:1.3.0")
}

擴充功能函式

適用於 LongSparseArray
運算子 Boolean LongSparseArray<T>.contains(key: Long)

如果集合包含,則傳回「是」。

Unit LongSparseArray<T>.forEach(action: (key: Long, value: T) -> Unit)

為每個鍵/值項目執行指定的動作

T LongSparseArray<T>.getOrDefault(key: Long, defaultValue: T)

傳回與相應的值。如果值不存在,則傳回 defaultValue

T LongSparseArray<T>.getOrElse(key: Long, defaultValue: () -> T)

傳回與相應的值;如果值不存在,則傳回 defaultValue 中的值。

Boolean LongSparseArray<T>.isNotEmpty()

如果集合包含元素,則傳回「是」。

LongIterator LongSparseArray<T>.keyIterator()

就集合的鍵傳回 iterator。

運算子 LongSparseArray<T> LongSparseArray<T>.plus(other: LongSparseArray<T>)

透過新增或取代其他集合的項目來建立新集合。

Boolean LongSparseArray<T>.remove(key: Long, value: T)

如果的項目對應至,則僅移除該項目。

運算子 Unit LongSparseArray<T>.set(key: Long, value: T)

允許使用索引運算子來儲存集合中的值。

Iterator<T> LongSparseArray<T>.valueIterator()

對集合的值傳回 iterator。

適用於 SparseArrayCompat
運算子 Boolean SparseArrayCompat<T>.contains(key: Int)

如果集合包含,則傳回「是」。

Unit SparseArrayCompat<T>.forEach(action: (key: Int, value: T) -> Unit)

為每個鍵/值項目執行指定的動作

T SparseArrayCompat<T>.getOrDefault(key: Int, defaultValue: T)

傳回與相應的值。如果值不存在,則傳回 defaultValue

T SparseArrayCompat<T>.getOrElse(key: Int, defaultValue: () -> T)

傳回與相應的值;如果值不存在,則傳回 defaultValue 中的值。

Boolean SparseArrayCompat<T>.isNotEmpty()

如果集合包含元素,則傳回「是」。

IntIterator SparseArrayCompat<T>.keyIterator()

就集合的鍵傳回 iterator。

運算子 SparseArrayCompat<T> SparseArrayCompat<T>.plus(other: SparseArrayCompat<T>)

透過新增或取代其他集合的項目來建立新集合。

Boolean SparseArrayCompat<T>.remove(key: Int, value: T)

如果的項目對應至,則僅移除該項目。

運算子 Unit SparseArrayCompat<T>.set(key: Int, value: T)

允許使用索引運算子來儲存集合中的值。

Iterator<T> SparseArrayCompat<T>.valueIterator()

對集合的值傳回 iterator。

擴充功能屬性

適用於 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.13.1"
}

Kotlin

dependencies {
    implementation("androidx.core:core-ktx:1.13.1")
}

擴充功能函式

適用於 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 = {})

使用提供的動作,將事件監聽器新增到這個動畫影片。

AnimatorPauseListener Animator.addPauseListener(crossinline onResume: (animator: Animator) -> Unit = {}, crossinline onPause: (animator: Animator) -> Unit = {})

使用提供的動作,將暫停和繼續事件監聽器新增到這個動畫影片。

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.13.1"
}

Kotlin

dependencies {
    implementation("androidx.core:core-ktx:1.13.1")
}

擴充功能函式

適用於 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 接收器上執行區塊

Unit Context.withStyledAttributes(@StyleRes resourceId: Int, attrs: IntArray, block: TypedArray.() -> Unit)

TypedArray 接收器上執行區塊

適用於 android.content.SharedPreferences
Unit SharedPreferences.edit(commit: Boolean = false, action: Editor.() -> Unit)

可透過呼叫套用修訂來編輯這個偏好設定執行個體,從而保留變更。

頂層函式

ContentValues contentValuesOf(vararg pairs: Pair<String, Any?>)

傳回具有指定鍵/值組合 (做為元素) 的新 ContentValues

androidx.core.content.res

依附元件

Groovy

dependencies {
    implementation "androidx.core:core-ktx:1.13.1"
}

Kotlin

dependencies {
    implementation("androidx.core:core-ktx:1.13.1")
}

擴充功能函式

適用於 android.content.res.TypedArray
Boolean TypedArray.getBooleanOrThrow(@StyleableRes index: Int)

索引中擷取屬性的布林值,如未定義,會擲回 IllegalArgumentException

Int TypedArray.getColorOrThrow(@StyleableRes index: Int)

索引中擷取屬性的色彩值,如未定義,會擲回 IllegalArgumentException

ColorStateList TypedArray.getColorStateListOrThrow(@StyleableRes index: Int)

索引中擷取屬性的色彩狀態清單值,如未定義,會擲回 IllegalArgumentException

Float TypedArray.getDimensionOrThrow(@StyleableRes index: Int)

索引中擷取屬性的維度值,如未定義,會擲回 IllegalArgumentException

Int TypedArray.getDimensionPixelOffsetOrThrow(@StyleableRes index: Int)

索引中擷取屬性的維度像素偏移值,如未定義,會擲回 IllegalArgumentException

Int TypedArray.getDimensionPixelSizeOrThrow(@StyleableRes index: Int)

索引中擷取屬性的維度像素尺寸值,如未定義,會擲回 IllegalArgumentException

Drawable TypedArray.getDrawableOrThrow(@StyleableRes index: Int)

索引中擷取屬性的可繪項目值,如未定義,會擲回 IllegalArgumentException

Float TypedArray.getFloatOrThrow(@StyleableRes index: Int)

索引中擷取屬性的浮點值,如未定義,會擲回 IllegalArgumentException

Typeface TypedArray.getFontOrThrow(@StyleableRes index: Int)

索引中擷取屬性的字型值,如未定義,會擲回 IllegalArgumentException

Int TypedArray.getIntOrThrow(@StyleableRes index: Int)

索引中擷取屬性的整數值,如未定義,會擲回 IllegalArgumentException

Int TypedArray.getIntegerOrThrow(@StyleableRes index: Int)

索引中擷取屬性的整數值,如未定義,會擲回 IllegalArgumentException

Int TypedArray.getResourceIdOrThrow(@StyleableRes index: Int)

索引中擷取屬性的資源 ID,如未定義,會擲回 IllegalArgumentException

String TypedArray.getStringOrThrow(@StyleableRes index: Int)

索引中擷取屬性的字串值,如未定義,會擲回 IllegalArgumentException

Array<CharSequence> TypedArray.getTextArrayOrThrow(@StyleableRes index: Int)

索引中擷取屬性的文字陣列值,如未定義,會擲回 IllegalArgumentException

CharSequence TypedArray.getTextOrThrow(@StyleableRes index: Int)

索引中擷取屬性的文字值,如未定義,會擲回 IllegalArgumentException

R TypedArray.use(block: (TypedArray) -> R)

在這個 TypedArray 上執行指定的區塊函式,然後再度使用。

androidx.core.database

依附元件

Groovy

dependencies {
    implementation "androidx.core:core-ktx:1.13.1"
}

Kotlin

dependencies {
    implementation("androidx.core:core-ktx:1.13.1")
}

擴充功能函式

適用於 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.13.1"
}

Kotlin

dependencies {
    implementation("androidx.core:core-ktx:1.13.1")
}

擴充功能函式

適用於 android.database.sqlite.SQLiteDatabase
T SQLiteDatabase.transaction(exclusive: Boolean = true, body: SQLiteDatabase.() -> T)

在交易中執行主體,如果執行完畢,且沒有例外狀況,則標記為成功。

androidx.core.graphics

依附元件

Groovy

dependencies {
    implementation "androidx.core:core-ktx:1.13.1"
}

Kotlin

dependencies {
    implementation("androidx.core:core-ktx:1.13.1")
}

擴充功能函式

適用於 android.graphics.Bitmap
Bitmap Bitmap.applyCanvas(block: Canvas.() -> Unit)

建立新的畫布,以繪製這幅點陣圖,並在新建立的畫布上執行指定的區塊

運算子 Boolean Bitmap.contains(p: Point)

如果指定的點位於點陣圖內,則傳回「是」。

運算子 Boolean Bitmap.contains(p: PointF)

如果指定的點位於點陣圖內,則傳回「是」。

運算子 Int Bitmap.get(x: Int, y: Int)

傳回指定位置中的像素值。

Bitmap Bitmap.scale(width: Int, height: Int, filter: Boolean = true)

建立新的點陣圖,可能的情況下在這幅點陣圖中縮放。

運算子 Unit Bitmap.set(x: Int, y: Int, color: Int)

在指定的 (x, y) 座標,將指定的顏色 int 寫入點陣圖 (假設可變動)。

適用於 android.graphics.Canvas
Unit Canvas.withClip(clipRect: Rect, block: Canvas.() -> Unit)

將指定的區塊納入對 Canvas.save/Canvas.clipRectCanvas.restoreToCount 的呼叫中。

Unit Canvas.withClip(clipRect: RectF, block: Canvas.() -> Unit)

將指定的區塊納入對 Canvas.save/Canvas.clipRectCanvas.restoreToCount 的呼叫中。

Unit Canvas.withClip(left: Int, top: Int, right: Int, bottom: Int, block: Canvas.() -> Unit)

將指定的區塊納入對 Canvas.save/Canvas.clipRectCanvas.restoreToCount 的呼叫中。

Unit Canvas.withClip(left: Float, top: Float, right: Float, bottom: Float, block: Canvas.() -> Unit)

將指定的區塊納入對 Canvas.save/Canvas.clipRectCanvas.restoreToCount 的呼叫中。

Unit Canvas.withClip(clipPath: Path, block: Canvas.() -> Unit)

將指定的區塊納入對 Canvas.save/Canvas.clipPathCanvas.restoreToCount 的呼叫中。

Unit Canvas.withMatrix(matrix: Matrix = Matrix(), block: Canvas.() -> Unit)

將指定的區塊納入對 Canvas.save/Canvas.concatCanvas.restoreToCount 的呼叫中。

Unit Canvas.withRotation(degrees: Float = 0.0f, pivotX: Float = 0.0f, pivotY: Float = 0.0f, block: Canvas.() -> Unit)

將指定的區塊納入對 Canvas.save/Canvas.rotateCanvas.restoreToCount 的呼叫中。

Unit Canvas.withSave(block: Canvas.() -> Unit)

將指定的區塊納入對 Canvas.saveCanvas.restoreToCount 的呼叫中。

Unit Canvas.withScale(x: Float = 1.0f, y: Float = 1.0f, pivotX: Float = 0.0f, pivotY: Float = 0.0f, block: Canvas.() -> Unit)

將指定的區塊納入對 Canvas.save/Canvas.scaleCanvas.restoreToCount 的呼叫中。

Unit Canvas.withSkew(x: Float = 0.0f, y: Float = 0.0f, block: Canvas.() -> Unit)

將指定的區塊納入對 Canvas.save/Canvas.skewCanvas.restoreToCount 的呼叫中。

Unit Canvas.withTranslation(x: Float = 0.0f, y: Float = 0.0f, block: Canvas.() -> Unit)

將指定的區塊納入對 Canvas.save/Canvas.translateCanvas.restoreToCount 的呼叫中。

適用於 android.graphics.Color
運算子 Float Color.component1()

傳回色彩的第一個元件。

運算子 Float Color.component2()

傳回色彩的第二個元件。

運算子 Float Color.component3()

傳回色彩的第三個元件。

運算子 Float Color.component4()

傳回色彩的第四個元件。

中置 Color! Color.convertTo(colorSpace: Named)

將色彩接收器轉換成指定色域中的色彩。

中置 Color! Color.convertTo(colorSpace: ColorSpace)

將色彩接收器轉換成指定色域中的色彩。

運算子 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)

從來源建立可繪項目

適用於 android.graphics.Matrix
運算子 Matrix Matrix.times(m: Matrix)

將此矩陣乘以另一個矩陣,然後傳回結果,用做新矩陣。

FloatArray Matrix.values()

傳回這個矩陣的 9 個值,用做新的浮點陣列。

適用於 android.graphics.Paint
Boolean Paint.setBlendMode(blendModeCompat: BlendModeCompat?)

一種便利方法,用於以回溯相容的方式設定顏料的 BlendMode。

適用於 android.graphics.Path
中置 Path Path.and(p: Path)

傳回兩條路徑的交集,用做新路徑

Iterable<PathSegment> Path.flatten(error: Float = 0.5f)

使用一系列線條區隔壓平合併 (或接近) 路徑

運算子 Path Path.minus(p: Path)

傳回兩條路徑的差異,用做新路徑

中置 Path Path.or(p: Path)

傳回兩條路徑的聯集,用做新路徑

運算子 Path Path.plus(p: Path)

傳回兩條路徑的聯集,用做新路徑

中置 Path Path.xor(p: Path)

傳回兩條路徑的聯集減交集,用做新路徑

適用於 android.graphics.Picture
Picture Picture.record(width: Int, height: Int, block: Canvas.() -> Unit)

建立新的畫布來記錄這張相片中的指令,並在新建立的畫布上執行指定的區塊,並傳回這張相片

適用於 android.graphics.Point
運算子 Int Point.component1()

傳回這個點的 x 座標。

運算子 Int Point.component2()

傳回這個點的 y 座標。

運算子 Point Point.minus(p: Point)

透過反向移動指定的點,使這個點發生偏移,並傳回結果,用做新的點。

運算子 Point Point.minus(xy: Int)

透過在 X 軸和 Y 軸上反向移動指定的距離,使這個點發生偏移,並傳回結果,用做新的點。

運算子 Point Point.plus(p: Point)

透過指定的點使這個點發生偏移,並傳回結果,用做新的點。

運算子 Point Point.plus(xy: Int)

透過在 X 和 Y 軸上移動指定的距離,使這個點發生偏移,並傳回結果,用做新的點。

PointF Point.toPointF()

傳回這個點的 PointF 表示法。

運算子 Point Point.unaryMinus()

傳回代表這個點對立點的的新點。

適用於 android.graphics.PointF
運算子 Float PointF.component1()

傳回這個點的 x 座標。

運算子 Float PointF.component2()

傳回這個點的 y 座標。

運算子 PointF PointF.minus(p: PointF)

透過反向移動指定的點,使這個點發生偏移,並傳回結果,用做新的點。

運算子 PointF PointF.minus(xy: Float)

透過在 X 軸和 Y 軸上反向移動指定的距離,使這個點發生偏移,並傳回結果,用做新的點。

運算子 PointF PointF.plus(p: PointF)

透過指定的點使這個點發生偏移,並傳回結果,用做新的點。

運算子 PointF PointF.plus(xy: Float)

透過在 X 和 Y 軸上移動指定的距離,使這個點發生偏移,並傳回結果,用做新的點。

Point PointF.toPoint()

傳回這個點的表示法。

運算子 PointF PointF.unaryMinus()

傳回代表這個點對立點的的新點。

適用於 android.graphics.PorterDuff.Mode
PorterDuffColorFilter Mode.toColorFilter(color: Int)

建立新的 PorterDuffColorFilter,藉此將這個 PorterDuff.Mode 用做 Alpha 版合成或混和模式和指定的色彩

PorterDuffXfermode Mode.toXfermode()

建立新的 PorterDuffXfermode,藉此將這個 PorterDuff.Mode 用做 Alpha 版合成或混和模式。

適用於 android.graphics.Rect
中置 Rect Rect.and(r: Rect)

傳回兩個矩形的交集,用做新矩形。

運算子 Int Rect.component1()

傳回「左」,即矩形的第一個元件。

運算子 Int Rect.component2()

傳回「頂」,即矩形的第二個元件。

運算子 Int Rect.component3()

傳回「右」,即矩形的第三個元件。

運算子 Int Rect.component4()

傳回「底」,即矩形的第四個元件。

運算子 Boolean Rect.contains(p: Point)

如果指定的點位於矩形內,則傳回「是」。

運算子 Region Rect.minus(r: Rect)

傳回這個矩形與指定矩形的差異,用做新區域。

運算子 Rect Rect.minus(xy: Int)

傳回新的矩形,用來代表透過在 X 軸和 Y 軸上反向移動指定的距離,使此矩形發生偏移。

運算子 Rect Rect.minus(xy: Point)

傳回新的矩形,用來代表透過反向移動指定的點,使此矩形發生偏移。

中置 Rect Rect.or(r: Rect)

傳回兩個矩形的聯集,用做新矩形。

運算子 Rect Rect.plus(r: Rect)

執行此矩形和指定矩形的聯集,並傳回結果,用做新矩形。

運算子 Rect Rect.plus(xy: Int)

傳回新的矩形,用來代表透過在 X 軸和 Y 軸上移動指定的距離,使此矩形發生偏移。

運算子 Rect Rect.plus(xy: Point)

傳回新的矩形,用來代表透過移動指定的點,使此矩形發生偏移。

運算子 Rect Rect.times(factor: Int)

傳回一個新的矩形,用來代表此矩形中藉由因數縮放的各個元件。

RectF Rect.toRectF()

傳回此矩形的 RectF 表示法。

Region Rect.toRegion()

傳回此矩形的區域表示法。

中置 Region Rect.xor(r: Rect)

傳回兩個矩形的聯集減交集,用做新區域。

適用於 android.graphics.RectF
中置 RectF RectF.and(r: RectF)

傳回兩個矩形的交集,用做新矩形。

運算子 Float RectF.component1()

傳回「左」,即矩形的第一個元件。

運算子 Float RectF.component2()

傳回「頂」,即矩形的第二個元件。

運算子 Float RectF.component3()

傳回「右」,即矩形的第三個元件。

運算子 Float RectF.component4()

傳回「底」,即矩形的第四個元件。

運算子 Boolean RectF.contains(p: PointF)

如果指定的點位於矩形內,則傳回「是」。

運算子 Region RectF.minus(r: RectF)

傳回這個矩形與指定矩形的差異,用做新區域。

運算子 RectF RectF.minus(xy: Float)

傳回新的矩形,用來代表透過在 X 軸和 Y 軸上反向移動指定的距離,使此矩形發生偏移。

運算子 RectF RectF.minus(xy: PointF)

傳回新的矩形,用來代表透過反向移動指定的點,使此矩形發生偏移。

中置 RectF RectF.or(r: RectF)

傳回兩個矩形的聯集,用做新矩形。

運算子 RectF RectF.plus(r: RectF)

執行此矩形和指定矩形的聯集,並傳回結果,用做新矩形。

運算子 RectF RectF.plus(xy: Float)

傳回新的矩形,用來代表透過在 X 軸和 Y 軸上移動指定的距離,使此矩形發生偏移。

運算子 RectF RectF.plus(xy: PointF)

傳回新的矩形,用來代表透過移動指定的點,使此矩形發生偏移。

運算子 RectF RectF.times(factor: Int)

傳回一個新的矩形,用來代表此矩形中藉由因數縮放的各個元件。

運算子 RectF RectF.times(factor: Float)

傳回一個新的矩形,用來代表此矩形中藉由因數縮放的各個元件。

Rect RectF.toRect()

傳回此矩形的矩形表示法。

Region RectF.toRegion()

傳回此矩形的區域表示法。

RectF RectF.transform(m: Matrix)

使用提供的矩陣轉換此矩形,並傳回此矩形。

中置 Region RectF.xor(r: RectF)

傳回兩個矩形的聯集減交集,用做新區域。

適用於 android.graphics.Region
中置 Region Region.and(r: Rect)

傳回此區域與指定矩形的交集,用做新區域。

中置 Region Region.and(r: Region)

傳回此區域與指定區域的交集,用做新區域。

運算子 Boolean Region.contains(p: Point)

如果區域包含指定的,則傳回「是」。

Unit Region.forEach(action: (rect: Rect) -> Unit)

對此區域內的每個矩形執行指定動作。

運算子 Iterator<Rect> Region.iterator()

傳回此區域內矩形的 Iterator

運算子 Region Region.minus(r: Rect)

傳回此區域與指定矩形的差異,用做新區域。

運算子 Region Region.minus(r: Region)

傳回此區域與指定區域的差異,用做新區域。

運算子 Region Region.not()

傳回此區域的對立區域,用做新區域。

中置 Region Region.or(r: Rect)

傳回此區域與指定矩形的聯集,用做新區域。

中置 Region Region.or(r: Region)

傳回此區域與指定區域的聯集,用做新區域。

運算子 Region Region.plus(r: Rect)

傳回此區域與指定矩形的聯集,用做新區域。

運算子 Region Region.plus(r: Region)

傳回此區域與指定區域的聯集,用做新區域。

運算子 Region Region.unaryMinus()

傳回此區域的對立區域,用做新區域。

中置 Region Region.xor(r: Rect)

傳回此區域與指定矩形的聯集減交集,用做新區域。

中置 Region Region.xor(r: Region)

傳回此區域與指定區域的聯集減交集,用做新區域。

適用於 android.graphics.Shader
Unit Shader.transform(block: Matrix.() -> Unit)

將指定的區塊納入對 Shader.getLocalMatrixShader.setLocalMatrix 的呼叫中。

適用於 kotlin.Int
運算子 Int Int.component1()

傳回色彩 int 的 Alpha 版元件。

運算子 Int Int.component2()

傳回色彩 int 的紅色元件。

運算子 Int Int.component3()

傳回色彩 int 的綠色元件。

運算子 Int Int.component4()

傳回色彩 int 的藍色元件。

中置 Long Int.convertTo(colorSpace: Named)

將色彩 int 接收器轉換成指定色域中的色彩長值。

中置 Long Int.convertTo(colorSpace: ColorSpace)

將色彩 int 接收器轉換成指定色域中的色彩長值。

Color Int.toColor()

從色彩 int 建立新的色彩執行個體。

Long Int.toColorLong()

將指定的 ARGB 色彩 int 轉換為 sRGB 色域的 RGBA 色彩長值

適用於 kotlin.Long
運算子 Float Long.component1()

傳回色彩的第一個元件。

運算子 Float Long.component2()

傳回色彩的第二個元件。

運算子 Float Long.component3()

傳回色彩的第三個元件。

運算子 Float Long.component4()

傳回色彩的第四個元件。

中置 Long Long.convertTo(colorSpace: Named)

將色彩長值接收器轉換成指定色域中的色彩長值。

中置 Long Long.convertTo(colorSpace: ColorSpace)

將色彩長值接收器轉換成指定色域中的色彩長值。

Color Long.toColor()

色彩長值建立新的色彩執行個體。

Int Long.toColorInt()

將指定的色彩長值轉換成 ARGB 色彩 int

適用於 kotlin.String
Int String.toColorInt()

傳回這個字串的相應 Int 色彩。

擴充功能屬性

適用於 kotlin.Int
Int Int.alpha()

傳回色彩 int 的 Alpha 版元件。

Int Int.blue()

傳回色彩 int 的藍色元件。

Int Int.green()

傳回色彩 int 的綠色元件。

Float Int.luminance()

傳回色彩 int 的相對亮度 (假設為 sRGB 編碼)。

Int Int.red()

傳回色彩 int 的紅色元件。

適用於 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)

建立旋轉矩陣。該矩陣以圍繞位於座標 (px, py) 的樞紐點的旋轉角度定義。

Matrix scaleMatrix(sx: Float = 1.0f, sy: Float = 1.0f)

建立縮放矩陣,使其縮放比例係數 sxsy 分別位於 x 軸和 y 軸上。

Matrix translationMatrix(tx: Float = 0.0f, ty: Float = 0.0f)

建立平移矩陣,使其平移量 txty 分別位於 x 軸和 y 軸上。

androidx.core.graphics.drawable

依附元件

Groovy

dependencies {
    implementation "androidx.core:core-ktx:1.13.1"
}

Kotlin

dependencies {
    implementation("androidx.core:core-ktx:1.13.1")
}

擴充功能函式

適用於 android.graphics.Bitmap
Icon Bitmap.toAdaptiveIcon()

使用這幅自動調整的點陣圖建立圖示

BitmapDrawable Bitmap.toDrawable(resources: Resources)

使用這幅點陣圖建立 BitmapDrawable

Icon Bitmap.toIcon()

使用這幅點陣圖建立圖示

適用於 android.graphics.Color
ColorDrawable Color.toDrawable()

使用這種色彩 (透過 Color.toArgb) 建立 ColorDrawable

適用於 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()

使用這個 Uri 建立圖示

適用於 kotlin.ByteArray
Icon ByteArray.toIcon()

使用這個 ByteArray 建立 圖示

適用於 kotlin.Int
ColorDrawable Int.toDrawable()

使用這個顏色值建立 ColorDrawable

androidx.core.location

依附元件

Groovy

dependencies {
    implementation "androidx.core:core-ktx:1.13.1"
}

Kotlin

dependencies {
    implementation("androidx.core:core-ktx:1.13.1")
}

擴充功能函式

適用於 android.location.Location
運算子 Double Location.component1()

傳回此位置的緯度。

運算子 Double Location.component2()

傳回此位置的經度。

androidx.core.net

依附元件

Groovy

dependencies {
    implementation "androidx.core:core-ktx:1.13.1"
}

Kotlin

dependencies {
    implementation("androidx.core:core-ktx:1.13.1")
}

擴充功能函式

適用於 android.net.Uri
File Uri.toFile()

使用指定的 Uri 建立檔案

適用於 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.13.1"
}

Kotlin

dependencies {
    implementation("androidx.core:core-ktx:1.13.1")
}

擴充功能函式

適用於 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?>)

傳回具有指定鍵/值組合 (做為元素) 的新套裝組合

PersistableBundle persistableBundleOf(vararg pairs: Pair<String, Any?>)

傳回具有指定鍵/值組合 (做為元素) 的新 PersistableBundle

T trace(sectionName: String, block: () -> T)

將指定的區塊納入對 Trace.beginSection (具有提供的 sectionName) 和 Trace.endSection 的呼叫中。

androidx.core.text

依附元件

Groovy

dependencies {
    implementation "androidx.core:core-ktx:1.13.1"
}

Kotlin

dependencies {
    implementation("androidx.core:core-ktx:1.13.1")
}

擴充功能函式

適用於 android.text.Spannable
Unit Spannable.clearSpans()

清除這段文字中的所有時距。

運算子 Unit Spannable.set(start: Int, end: Int, span: Any)

時距新增至文字的開始結束範圍。

運算子 Unit Spannable.set(range: IntRange, span: Any)

時距新增至文字的範圍

適用於 android.text.SpannableStringBuilder
SpannableStringBuilder SpannableStringBuilder.backgroundColor(color: Int, builderAction: SpannableStringBuilder.() -> Unit)

builderAction 內的附加文字納入 BackgroundColorSpan 中。

SpannableStringBuilder SpannableStringBuilder.bold(builderAction: SpannableStringBuilder.() -> Unit)

builderAction 內的附加文字納入粗體的 StyleSpan 中。

SpannableStringBuilder SpannableStringBuilder.color(color: Int, builderAction: SpannableStringBuilder.() -> Unit)

builderAction 內的附加文字納入 ForegroundColorSpan 中。

SpannableStringBuilder SpannableStringBuilder.inSpans(vararg spans: Any, builderAction: SpannableStringBuilder.() -> Unit)

builderAction 內的附加文字納入時距中。

SpannableStringBuilder SpannableStringBuilder.inSpans(span: Any, builderAction: SpannableStringBuilder.() -> Unit)

builderAction 內的附加文字納入時距中。

SpannableStringBuilder SpannableStringBuilder.italic(builderAction: SpannableStringBuilder.() -> Unit)

builderAction 內的附加文字納入斜體的 StyleSpan 中。

SpannableStringBuilder SpannableStringBuilder.scale(proportion: Float, builderAction: SpannableStringBuilder.() -> Unit)

builderAction 內的附加文字納入 RelativeSizeSpan 中。

SpannableStringBuilder SpannableStringBuilder.strikeThrough(builderAction: SpannableStringBuilder.() -> Unit)

builderAction 內的附加文字納入 StrikethroughSpan 中。

SpannableStringBuilder SpannableStringBuilder.subscript(builderAction: SpannableStringBuilder.() -> Unit)

builderAction 內的附加文字納入 SubscriptSpan 中。

SpannableStringBuilder SpannableStringBuilder.superscript(builderAction: SpannableStringBuilder.() -> Unit)

builderAction 內的附加文字納入 SuperscriptSpan 中。

SpannableStringBuilder SpannableStringBuilder.underline(builderAction: SpannableStringBuilder.() -> Unit)

builderAction 內的附加文字納入 UnderlineSpan 中。

適用於 android.text.Spanned
Array<out T> Spanned.getSpans(start: Int = 0, end: Int = length)

獲取做為 T 的執行個體的所有時距。

String Spanned.toHtml(option: Int = TO_HTML_PARAGRAPH_LINES_CONSECUTIVE)

從這個 Spanned 的時距傳回 HTML 的字串。

適用於 kotlin.CharSequence
Boolean CharSequence.isDigitsOnly()

傳回指定的 CharSequence 是否只包含數字。

Spannable CharSequence.toSpannable()

CharSequence 傳回新的 Spannable,或如果來源是 SpannableString 的執行個體,則傳回來源本身。

Spanned CharSequence.toSpanned()

CharSequence 傳回新的 Spanned,或如果來源是 SpannedString 的執行個體,則傳回來源本身。

Int CharSequence.trimmedLength()

如果使用 String.trim,從開始位置到結束位置剪輯空格和 ASCII 控制字元,則傳回指定的 CharSequence 本應具有的長度。

適用於 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.13.1"
}

Kotlin

dependencies {
    implementation("androidx.core:core-ktx:1.13.1")
}

擴充功能函式

適用於 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 = {})

使用提供的動作,將事件監聽器新增到這次轉換。

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.13.1"
}

Kotlin

dependencies {
    implementation("androidx.core:core-ktx:1.13.1")
}

擴充功能函式

適用於 android.util.AtomicFile
ByteArray AtomicFile.readBytes()

獲取此檔案的全部內容,來用做位元組陣列。

String AtomicFile.readText(charset: Charset = Charsets.UTF_8)

獲取此檔案的全部內容,來用做使用 UTF-8 或指定字元集的字串。

Unit AtomicFile.tryWrite(block: (out: FileOutputStream) -> Unit)

在此檔案的區塊內行寫入作業。

Unit AtomicFile.writeBytes(array: ByteArray)

將此檔案的內容設為位元組陣列

Unit AtomicFile.writeText(text: String, charset: Charset = Charsets.UTF_8)

將此檔案的內容設為使用 UTF-8 或指定字元集的已編碼文字

適用於 android.util.LongSparseArray
運算子 Boolean LongSparseArray<T>.contains(key: Long)

如果集合包含,則傳回「是」。

Boolean LongSparseArray<T>.containsKey(key: Long)

如果集合包含,則傳回「是」。

Boolean LongSparseArray<T>.containsValue(value: T)

如果集合包含,則傳回「是」。

Unit LongSparseArray<T>.forEach(action: (key: Long, value: T) -> Unit)

為每個鍵/值項目執行指定的動作

T LongSparseArray<T>.getOrDefault(key: Long, defaultValue: T)

傳回與相應的值。如果值不存在,則傳回 defaultValue

T LongSparseArray<T>.getOrElse(key: Long, defaultValue: () -> T)

傳回與相應的值;如果值不存在,則傳回 defaultValue 中的值。

Boolean LongSparseArray<T>.isEmpty()

如果集合不含元素,則傳回「是」。

Boolean LongSparseArray<T>.isNotEmpty()

如果集合包含元素,則傳回「是」。

LongIterator LongSparseArray<T>.keyIterator()

就集合的鍵傳回 iterator。

運算子 LongSparseArray<T> LongSparseArray<T>.plus(other: LongSparseArray<T>)

透過新增或取代其他集合的項目來建立新集合。

Unit LongSparseArray<T>.putAll(other: LongSparseArray<T>)

透過新增或取代其他集合的項目來更新此集合。

Boolean LongSparseArray<T>.remove(key: Long, value: T)

如果的項目對應至,則僅移除該項目。

運算子 Unit LongSparseArray<T>.set(key: Long, value: T)

允許使用索引運算子來儲存集合中的值。

Iterator<T> LongSparseArray<T>.valueIterator()

對集合的值傳回 iterator。

適用於 android.util.Pair
運算子 F Pair<F, S>.component1()

傳回配對的第一個元件。

運算子 S Pair<F, S>.component2()

傳回配對的第二個元件。

Pair<F, S> Pair<F, S>.toKotlinPair()

傳回此配對,用做 kotlin.Pair

適用於 android.util.Range
中置 Range<T> Range<T>.and(other: Range<T>)

傳回這個範圍與其他範圍的交集。

運算子 Range<T> Range<T>.plus(value: T)

傳回包含此範圍和的最小範圍。

運算子 Range<T> Range<T>.plus(other: Range<T>)

傳回包含此範圍和其他範圍的最小範圍。

ClosedRange<T> Range<T>.toClosedRange()

傳回此範圍,用做 ClosedRange

適用於 android.util.Size
運算子 Int Size.component1()

傳回「寬度」,即這個尺寸的第一個元件。

運算子 Int Size.component2()

傳回「高度」,即這個尺寸的第二個元件。

適用於 android.util.SizeF
運算子 Float SizeF.component1()

傳回「寬度」,即這個 SizeF 的第一個元件。

運算子 Float SizeF.component2()

傳回「高度」,即這個 SizeF 的第二個元件。

適用於 android.util.SparseArray
運算子 Boolean SparseArray<T>.contains(key: Int)

如果集合包含,則傳回「是」。

Boolean SparseArray<T>.containsKey(key: Int)

如果集合包含,則傳回「是」。

Boolean SparseArray<T>.containsValue(value: T)

如果集合包含,則傳回「是」。

Unit SparseArray<T>.forEach(action: (key: Int, value: T) -> Unit)

為每個鍵/值項目執行指定的動作

T SparseArray<T>.getOrDefault(key: Int, defaultValue: T)

傳回與相應的值。如果值不存在,則傳回 defaultValue

T SparseArray<T>.getOrElse(key: Int, defaultValue: () -> T)

傳回與相應的值;如果值不存在,則傳回 defaultValue 中的值。

Boolean SparseArray<T>.isEmpty()

如果集合不含元素,則傳回「是」。

Boolean SparseArray<T>.isNotEmpty()

如果集合包含元素,則傳回「是」。

IntIterator SparseArray<T>.keyIterator()

就集合的鍵傳回 iterator。

運算子 SparseArray<T> SparseArray<T>.plus(other: SparseArray<T>)

透過新增或取代其他集合的項目來建立新集合。

Unit SparseArray<T>.putAll(other: SparseArray<T>)

透過新增或取代其他集合的項目來更新此集合。

Boolean SparseArray<T>.remove(key: Int, value: T)

如果的項目對應至,則僅移除該項目。

運算子 Unit SparseArray<T>.set(key: Int, value: T)

允許使用索引運算子來儲存集合中的值。

Iterator<T> SparseArray<T>.valueIterator()

對集合的值傳回 iterator。

適用於 android.util.SparseBooleanArray
運算子 Boolean SparseBooleanArray.contains(key: Int)

如果集合包含,則傳回「是」。

Boolean SparseBooleanArray.containsKey(key: Int)

如果集合包含,則傳回「是」。

Boolean SparseBooleanArray.containsValue(value: Boolean)

如果集合包含,則傳回「是」。

Unit SparseBooleanArray.forEach(action: (key: Int, value: Boolean) -> Unit)

為每個鍵/值項目執行指定的動作

Boolean SparseBooleanArray.getOrDefault(key: Int, defaultValue: Boolean)

傳回與相應的值。如果值不存在,則傳回 defaultValue

Boolean SparseBooleanArray.getOrElse(key: Int, defaultValue: () -> Boolean)

傳回與相應的值;如果值不存在,則傳回 defaultValue 中的值。

Boolean SparseBooleanArray.isEmpty()

如果集合不含元素,則傳回「是」。

Boolean SparseBooleanArray.isNotEmpty()

如果集合包含元素,則傳回「是」。

IntIterator SparseBooleanArray.keyIterator()

就集合的鍵傳回 iterator。

運算子 SparseBooleanArray SparseBooleanArray.plus(other: SparseBooleanArray)

透過新增或取代其他集合的項目來建立新集合。

Unit SparseBooleanArray.putAll(other: SparseBooleanArray)

透過新增或取代其他集合的項目來更新此集合。

Boolean SparseBooleanArray.remove(key: Int, value: Boolean)

如果的項目對應至,則僅移除該項目。

運算子 Unit SparseBooleanArray.set(key: Int, value: Boolean)

允許使用索引運算子來儲存集合中的值。

BooleanIterator SparseBooleanArray.valueIterator()

對集合的值傳回 iterator。

適用於 android.util.SparseIntArray
運算子 Boolean SparseIntArray.contains(key: Int)

如果集合包含,則傳回「是」。

Boolean SparseIntArray.containsKey(key: Int)

如果集合包含,則傳回「是」。

Boolean SparseIntArray.containsValue(value: Int)

如果集合包含,則傳回「是」。

Unit SparseIntArray.forEach(action: (key: Int, value: Int) -> Unit)

為每個鍵/值項目執行指定的動作

Int SparseIntArray.getOrDefault(key: Int, defaultValue: Int)

傳回與相應的值。如果值不存在,則傳回 defaultValue

Int SparseIntArray.getOrElse(key: Int, defaultValue: () -> Int)

傳回與相應的值;如果值不存在,則傳回 defaultValue 中的值。

Boolean SparseIntArray.isEmpty()

如果集合不含元素,則傳回「是」。

Boolean SparseIntArray.isNotEmpty()

如果集合包含元素,則傳回「是」。

IntIterator SparseIntArray.keyIterator()

就集合的鍵傳回 iterator。

運算子 SparseIntArray SparseIntArray.plus(other: SparseIntArray)

透過新增或取代其他集合的項目來建立新集合。

Unit SparseIntArray.putAll(other: SparseIntArray)

透過新增或取代其他集合的項目來更新此集合。

Boolean SparseIntArray.remove(key: Int, value: Int)

如果的項目對應至,則僅移除該項目。

運算子 Unit SparseIntArray.set(key: Int, value: Int)

允許使用索引運算子來儲存集合中的值。

IntIterator SparseIntArray.valueIterator()

對集合的值傳回 iterator。

適用於 android.util.SparseLongArray
運算子 Boolean SparseLongArray.contains(key: Int)

如果集合包含,則傳回「是」。

Boolean SparseLongArray.containsKey(key: Int)

如果集合包含,則傳回「是」。

Boolean SparseLongArray.containsValue(value: Long)

如果集合包含,則傳回「是」。

Unit SparseLongArray.forEach(action: (key: Int, value: Long) -> Unit)

為每個鍵/值項目執行指定的動作

Long SparseLongArray.getOrDefault(key: Int, defaultValue: Long)

傳回與相應的值。如果值不存在,則傳回 defaultValue

Long SparseLongArray.getOrElse(key: Int, defaultValue: () -> Long)

傳回與相應的值;如果值不存在,則傳回 defaultValue 中的值。

Boolean SparseLongArray.isEmpty()

如果集合不含元素,則傳回「是」。

Boolean SparseLongArray.isNotEmpty()

如果集合包含元素,則傳回「是」。

IntIterator SparseLongArray.keyIterator()

就集合的鍵傳回 iterator。

運算子 SparseLongArray SparseLongArray.plus(other: SparseLongArray)

透過新增或取代其他集合的項目來建立新集合。

Unit SparseLongArray.putAll(other: SparseLongArray)

透過新增或取代其他集合的項目來更新此集合。

Boolean SparseLongArray.remove(key: Int, value: Long)

如果的項目設為,則僅移除該項目。

運算子 Unit SparseLongArray.set(key: Int, value: Long)

允許使用索引運算子來儲存集合中的值。

LongIterator SparseLongArray.valueIterator()

對集合的值傳回 iterator。

適用於 kotlin.Double
Half Double.toHalf()

傳回代表指定雙精度浮點值半精度浮點值執行個體。

適用於 kotlin.Float
Half Float.toHalf()

傳回代表指定浮點值半精度浮點值執行個體。

適用於 kotlin.Pair
Pair<F, S> Pair<F, S>.toAndroidPair()

傳回這個 kotlin.Pair,用做 Android 配對

適用於 kotlin.Short
Half Short.toHalf()

傳回代表指定短值半精度浮點值執行個體。

適用於 kotlin.String
Half String.toHalf()

傳回代表指定字串半精度浮點值執行個體。

適用於 kotlin.ranges.ClosedRange
Range<T> ClosedRange<T>.toRange()

傳回這個 ClosedRange,用做範圍

擴充功能屬性

適用於 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

中置 Range<T> T.rangeTo(that: T)

建立從這個可比較值到該值的範圍。

androidx.core.view

依附元件

Groovy

dependencies {
    implementation "androidx.core:core-ktx:1.13.1"
}

Kotlin

dependencies {
    implementation("androidx.core:core-ktx:1.13.1")
}

擴充功能函式

適用於 android.view.Menu
運算子 Boolean Menu.contains(item: MenuItem)

如果在這個選單中找到項目,則傳回「true」。

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

對此選單內的每個項目執行指定動作。

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

對此選單內的每個項目執行指定動作,並提供依序索引。

運算子 MenuItem Menu.get(index: Int)

傳回索引的選單。

Boolean Menu.isEmpty()

如果這個選單不含任何項目,則傳回「是」。

Boolean Menu.isNotEmpty()

如果這個選單包含一個或多個項目,則傳回「是」。

運算子 MutableIterator<MenuItem> Menu.iterator()

對這個選單內的項目傳回 MutableIterator

運算子 Unit Menu.minusAssign(item: MenuItem)

從這個選單中移除項目

適用於 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 執行區塊,並使用更新後的版本重新指派 layoutParams。

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

使用檢視畫面的 layoutParams 型別版本執行區塊,並使用更新後的版本重新指派 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
運算子 Boolean ViewGroup.contains(view: View)

如果這個檢視區塊群組中找到檢視畫面,則傳回「true」。

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

對此檢視區塊群組內的每個檢視畫面執行指定動作。

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

對此檢視區塊群組內的每個檢視畫面執行指定動作,並提供依序索引。

運算子 View ViewGroup.get(index: Int)

傳回索引的檢視畫面。

Boolean ViewGroup.isEmpty()

如果這個檢視區塊群組不含檢視畫面,則傳回「是」。

Boolean ViewGroup.isNotEmpty()

如果這個檢視區塊群組包含一個或多個檢視畫面,則傳回「是」。

運算子 MutableIterator<View> ViewGroup.iterator()

對這個檢視區塊群組內的檢視畫面傳回 MutableIterator

運算子 Unit ViewGroup.minusAssign(view: View)

從這個檢視區塊群組中移除檢視畫面

運算子 Unit ViewGroup.plusAssign(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()

對這個選單內的項目傳回序列

Int Menu.size()

傳回這個選單內的項目數量。

適用於 android.view.View
Boolean View.isGone()

在這個檢視畫面的瀏覽權限為 View.GONE 時,傳回「是」,否則傳回「否」。

Boolean View.isInvisible()

在這個檢視畫面的瀏覽權限為 View.INVISIBLE 時,傳回「是」,否則傳回「否」。

Boolean View.isVisible()

在這個檢視畫面的瀏覽權限為 View.VISIBLE 時,傳回「是」,否則傳回「否」。

Int View.marginBottom()

如果這個檢視畫面的 LayoutParamsViewGroup.MarginLayoutParams,則傳回底部邊界,否則傳回「0」。

Int View.marginEnd()

如果這個檢視畫面的 LayoutParamsViewGroup.MarginLayoutParams,則傳回結束邊界,否則傳回「0」。

Int View.marginLeft()

如果這個檢視畫面的 LayoutParamsViewGroup.MarginLayoutParams,則傳回左側邊界,否則傳回「0」。

Int View.marginRight()

如果這個檢視畫面的 LayoutParamsViewGroup.MarginLayoutParams,則傳回右側邊界,否則傳回「0」。

Int View.marginStart()

如果這個檢視畫面的 LayoutParamsViewGroup.MarginLayoutParams,則傳回開始邊界,否則傳回「0」。

Int View.marginTop()

如果這個檢視畫面的 LayoutParamsViewGroup.MarginLayoutParams,則傳回頂部邊界,否則傳回「0」。

適用於 android.view.ViewGroup
Sequence<View> ViewGroup.children()

對這個檢視區塊群組內的子檢視畫面傳回序列

Int ViewGroup.size()

傳回這個檢視區塊群組內的檢視畫面數目。

androidx.core.widget

依附元件

Groovy

dependencies {
    implementation "androidx.core:core-ktx:1.13.1"
}

Kotlin

dependencies {
    implementation("androidx.core:core-ktx:1.13.1")
}

擴充功能函式

適用於 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:1.1.0-alpha03"
}

Kotlin

dependencies {
    implementation("androidx.dynamicanimation:dynamicanimation-ktx:1.1.0-alpha03")
}

擴充功能函式

適用於 SpringAnimation
SpringAnimation SpringAnimation.withSpringForceProperties(func: SpringForce.() -> Unit)

在 SpringAnimation 上更新或套用彈簧力屬性,例如 SpringForce.mDampingRatioSpringForce.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.6.2"
}

Kotlin

dependencies {
    implementation("androidx.fragment:fragment-ktx:1.6.2")
}

擴充功能函式

適用於 android.view.View
F View.findFragment()

找出與檢視畫面關聯的片段

適用於片段
Lazy<VM> Fragment.activityViewModels(noinline factoryProducer: () -> ViewModelProvider.Factory = null)

傳回屬性委派,以存取父項活動的 ViewModel。如果指定了 factoryProducer,則其傳回的 ViewModelProvider.Factory 會用來首次建立 ViewModel

Lazy<VM> Fragment.createViewModelLazy(viewModelClass: KClass<VM>, storeProducer: () -> ViewModelStore, factoryProducer: () -> ViewModelProvider.Factory = null)

建立 ViewModelLazy 的輔助方法,用於解析做為 factoryProducer 而傳遞至預設工廠的 null

Lazy<VM> Fragment.viewModels(noinline ownerProducer: () -> ViewModelStoreOwner = { this }, noinline factoryProducer: () -> ViewModelProvider.Factory = null)

傳回屬性委派,來存取根據預設使範圍限定在此片段內的 ViewModel

適用於 FragmentTransaction
FragmentTransaction FragmentTransaction.add(@IdRes containerViewId: Int, tag: String? = null, args: Bundle? = null)

將片段新增至關聯的 FragmentManager,並將片段的檢視畫面加載至 containerViewId 指定的容器檢視畫面中,稍後即可透過 FragmentManager.findFragmentById 擷取。

FragmentTransaction FragmentTransaction.add(tag: String, args: Bundle? = null)

將片段新增至關聯的 FragmentManager,但沒有將片段新增至任何容器檢視畫面中。

FragmentTransaction FragmentTransaction.replace(@IdRes containerViewId: Int, tag: String? = null, args: Bundle? = null)

取代已新增至容器的現有片段。

適用於 FragmentManager
Unit FragmentManager.commit(allowStateLoss: Boolean = false, body: FragmentTransaction.() -> Unit)

FragmentTransaction 中執行主體。如果完成時沒有例外狀況,則自動修訂該物件。

Unit FragmentManager.commitNow(allowStateLoss: Boolean = false, body: FragmentTransaction.() -> Unit)

FragmentTransaction 中執行主體。如果完成時沒有例外狀況,則自動修訂該物件。

Unit FragmentManager.transaction(now: Boolean = false, allowStateLoss: Boolean = false, body: FragmentTransaction.() -> Unit)

FragmentTransaction 中執行主體。如果完成時沒有例外狀況,則自動修訂該物件。

androidx.fragment.app.testing

依附元件

Groovy

dependencies {
    implementation "androidx.fragment:fragment-testing:1.6.2"
}

Kotlin

dependencies {
    implementation("androidx.fragment:fragment-testing:1.6.2")
}

頂層函式

FragmentScenario<F!> launchFragment(fragmentArgs: Bundle? = null, @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, factory: FragmentFactory? = null)

使用指定的 FragmentFactory 啟動包含由空白 FragmentActivity 代管的指定引數的片段,並等待該片段達到已繼續狀態。

FragmentScenario<F!> launchFragment(fragmentArgs: Bundle? = null, @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, crossinline instantiate: () -> F)

使用執行個體化 啟動包含由空白 FragmentActivity 代管的指定引數的片段,以建立該片段,並等待該片段達到已繼續狀態。

FragmentScenario<F!> launchFragmentInContainer(fragmentArgs: Bundle? = null, @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, factory: FragmentFactory? = null)

在活動的根層級檢視畫面容器 android.R.id.content 中,啟動包含由空白 FragmentActivity 代管的指定引數的片段,並等待該片段達到已繼續狀態。

FragmentScenario<F!> launchFragmentInContainer(fragmentArgs: Bundle? = null, @StyleRes themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, crossinline instantiate: () -> F)

在活動的根層級檢視畫面容器 android.R.id.content 中,使用 執行個體化 啟動包含由空白 FragmentActivity 代管的指定引數的片段,以建立該片段,並等待該片段達到已繼續狀態。

androidx.lifecycle

依附元件

Groovy

dependencies {
    implementation "androidx.lifecycle:lifecycle-livedata-core-ktx:2.6.2"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.6.2"
    implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:2.6.2"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.2"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2"
}

Kotlin

dependencies {
    implementation("androidx.lifecycle:lifecycle-livedata-core-ktx:2.6.2")
    implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.6.2")
    implementation("androidx.lifecycle:lifecycle-reactivestreams-ktx:2.6.2")
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
    implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2")
}

擴充功能函式

適用於 kotlinx.coroutines.flow.Flow
LiveData<T> Flow<T>.asLiveData(context: CoroutineContext = EmptyCoroutineContext, timeoutInMs: Long = DEFAULT_TIMEOUT)

建立包含從原始資料流收集的值的 LiveData。

LiveData<T> Flow<T>.asLiveData(context: CoroutineContext = EmptyCoroutineContext, timeout: Duration)

建立包含從原始資料流收集的值的 LiveData。

適用於 org.reactivestreams.Publisher
LiveData<T> Publisher<T>.toLiveData()

從 ReactiveStreams 發布者建立可觀測的 LiveData 串流。

適用於 LiveData
Flow<T> LiveData<T>.asFlow()

在資料流收集器收到 LiveData 保持的最後一個值時,建立包含由原始 LiveData 調派的值的資料流,然後觀測 LiveData 更新。

LiveData<X> LiveData<X>.distinctUntilChanged()

建立新的 LiveData 物件後,只有在來源 this LiveData 值變更時,才會發送值。

LiveData<Y> LiveData<X>.map(crossinline transform: (X) -> Y)

透過將轉換套用至 this LiveData 上設定的每個值,傳回與 this LiveData 對應的 LiveData

Observer<T> LiveData<T>.observe(owner: LifecycleOwner, crossinline onChanged: (T) -> Unit)

將指定的 onChanged lambda 新增為指定擁有者有效期內的觀察者,並傳回觀察者的參照。

LiveData<Y> LiveData<X>.switchMap(crossinline transform: (X) -> LiveData<Y>)

透過將轉換套用至 this 上設定的每個值,傳回與輸入內容 this LiveData 對應的 LiveData

Publisher<T> LiveData<T>.toPublisher(lifecycle: LifecycleOwner)

將指定的 LiveData 串流調整為 ReactiveStreams 發布者

適用於 ViewModelProvider
VM ViewModelProvider.get()

傳回現有的 ViewModel,或在該範圍 (通常是片段或活動) 內建立與此 ViewModelProvider 關聯的新 ViewModel。

適用於 LifecycleOwner
suspend T LifecycleOwner.whenCreated(block: suspend CoroutineScope.() -> T)

LifecycleOwner生命週期至少處於 Lifecycle.State.CREATED 狀態時,就會執行指定區塊。

suspend T LifecycleOwner.whenResumed(block: suspend CoroutineScope.() -> T)

LifecycleOwner生命週期至少處於 Lifecycle.State.RESUMED 狀態時,就會執行指定區塊。

suspend T LifecycleOwner.whenStarted(block: suspend CoroutineScope.() -> T)

LifecycleOwner生命週期至少處於 Lifecycle.State.STARTED 狀態時,就會執行指定區塊。

適用於生命週期
suspend T Lifecycle.whenCreated(block: suspend CoroutineScope.() -> T)

生命週期至少處於 Lifecycle.State.CREATED 狀態時,就會執行指定區塊。

suspend T Lifecycle.whenResumed(block: suspend CoroutineScope.() -> T)

生命週期至少處於 Lifecycle.State.RESUMED 狀態時,就會執行指定區塊。

suspend T Lifecycle.whenStarted(block: suspend CoroutineScope.() -> T)

生命週期至少處於 Lifecycle.State.STARTED 狀態時,就會執行指定區塊。

suspend T Lifecycle.whenStateAtLeast(minState: Lifecycle.State, block: suspend CoroutineScope.() -> T)

CoroutineDispatcher 上執行指定的區塊,這個區塊會在主執行緒上執行區塊,並暫停執行作業,除非 Lifecycle 的狀態為至少 minState

擴充功能屬性

適用於生命週期
LifecycleCoroutineScope Lifecycle.coroutineScope()

與此生命週期連結的 CoroutineScope

適用於 LifecycleOwner
LifecycleCoroutineScope LifecycleOwner.lifecycleScope()

與此 LifecycleOwner生命週期連結的 CoroutineScope

適用於 ViewModel
CoroutineScope ViewModel.viewModelScope()

與此 ViewModel 連結的 CoroutineScope

頂層函式

LiveData<T> liveData(context: CoroutineContext = EmptyCoroutineContext, timeoutInMs: Long = DEFAULT_TIMEOUT, block: suspend LiveDataScope<T>.() -> Unit)

建構一個 LiveData,其中包含從在 LiveDataScope 上執行的特定區塊產生的值。

LiveData<T> liveData(context: CoroutineContext = EmptyCoroutineContext, timeout: Duration, block: suspend LiveDataScope<T>.() -> Unit)

建構一個 LiveData,其中包含從在 LiveDataScope 上執行的特定區塊產生的值。

androidx.navigation

依附元件

Groovy

dependencies {
    implementation "androidx.navigation:navigation-runtime-ktx:2.7.5"
    implementation "androidx.navigation:navigation-fragment-ktx:2.7.5"
    implementation "androidx.navigation:navigation-ui-ktx:2.7.5"
}

Kotlin

dependencies {
    implementation("androidx.navigation:navigation-runtime-ktx:2.7.5")
    implementation("androidx.navigation:navigation-fragment-ktx:2.7.5")
    implementation("androidx.navigation:navigation-ui-ktx:2.7.5")
}

擴充功能函式

適用於 android.app.Activity
NavController Activity.findNavController(@IdRes viewId: Int)

依據檢視畫面的 ID 及其包含活動,找出 NavController

NavArgsLazy<Args> Activity.navArgs()

傳回延遲委派,來存取活動的額外項目,用做 Args 執行個體。

適用於 android.view.View
NavController View.findNavController()

找出與檢視畫面關聯的 NavController

適用於 NavGraphBuilder
Unit NavGraphBuilder.activity(@IdRes id: Int, builder: ActivityNavigatorDestinationBuilder.() -> Unit)

建構新的 ActivityNavigator.Destination

Unit NavGraphBuilder.navigation(@IdRes id: Int, @IdRes startDestination: Int, builder: NavGraphBuilder.() -> Unit)

建構巢狀 NavGraph

適用於 NavGraph
運算子 Boolean NavGraph.contains(@IdRes id: Int)

如果此導覽圖找到包含 id 的目的地,則傳回 true

運算子 NavDestination NavGraph.get(@IdRes id: Int)

傳回包含 id 的目的地。

運算子 Unit NavGraph.minusAssign(node: NavDestination)

從此導覽圖中移除「node」。

運算子 Unit NavGraph.plusAssign(node: NavDestination)

將目的地新增至這個 NavGraph。

運算子 Unit NavGraph.plusAssign(other: NavGraph)

將其他集合中的所有目的地新增至這個集合。

適用於 NavController
NavGraph NavController.createGraph(@IdRes id: Int = 0, @IdRes startDestination: Int, builder: NavGraphBuilder.() -> Unit)

建構新的 NavGraph

適用於 NavHost
NavGraph NavHost.createGraph(@IdRes id: Int = 0, @IdRes startDestination: Int, builder: NavGraphBuilder.() -> Unit)

建構新的 NavGraph

適用於 NavigatorProvider
運算子 T NavigatorProvider.get(name: String)

依名稱擷取已註冊的導覽器

運算子 T NavigatorProvider.get(clazz: KClass<T>)

使用 Navigator.Name 註解提供的名稱,來擷取已註冊的導覽器

NavGraph NavigatorProvider.navigation(@IdRes id: Int = 0, @IdRes startDestination: Int, builder: NavGraphBuilder.() -> Unit)

建構新的 NavGraph

運算子 Unit NavigatorProvider.plusAssign(navigator: Navigator<out NavDestination>)

使用 Navigator.Name 註解提供的名稱,來註冊導覽器。

運算子 Navigator<out NavDestination!>? NavigatorProvider.set(name: String, navigator: Navigator<out NavDestination>)

依名稱註冊導覽器

適用於片段
Lazy<VM> Fragment.navGraphViewModels(@IdRes navGraphId: Int, noinline factoryProducer: () -> ViewModelProvider.Factory = null)

傳回屬性委派,來存取範圍限定在 {@link NavController} 返回堆疊上存在的導覽圖的 ViewModel

頂層函式

ActivityNavigator.Extras ActivityNavigatorExtras(activityOptions: ActivityOptionsCompat? = null, flags: Int = 0)

使用特定的 ActivityOptionsCompat 執行個體和/或任何 Intent.FLAG_ACTIVITY_ 旗標,建立新的 ActivityNavigator.Extras 執行個體。

NavOptions navOptions(optionsBuilder: NavOptionsBuilder.() -> Unit)

建立新的 NavOptions

androidx.navigation.fragment

依附元件

Groovy

dependencies {
    implementation "androidx.navigation:navigation-fragment-ktx:2.7.5"
}

Kotlin

dependencies {
    implementation("androidx.navigation:navigation-fragment-ktx:2.7.5")
}

擴充功能函式

適用於 NavGraphBuilder
Unit NavGraphBuilder.dialog(@IdRes id: Int)

建構新的 DialogFragmentNavigator.Destination

Unit NavGraphBuilder.dialog(@IdRes id: Int, builder: DialogFragmentNavigatorDestinationBuilder.() -> Unit)

建構新的 DialogFragmentNavigator.Destination

Unit NavGraphBuilder.fragment(@IdRes id: Int)

建構新的 FragmentNavigator.Destination

Unit NavGraphBuilder.fragment(@IdRes id: Int, builder: FragmentNavigatorDestinationBuilder.() -> Unit)

建構新的 FragmentNavigator.Destination

適用於片段
NavController Fragment.findNavController()

依據片段找出 NavController

NavArgsLazy<Args> Fragment.navArgs()

傳回延遲委派,來存取片段的引數,用做 Args 執行個體。

頂層函式

FragmentNavigator.Extras FragmentNavigatorExtras(vararg sharedElements: Pair<View, String>)

使用指定的共用元素,建立新的 FragmentNavigator.Extras 執行個體

androidx.navigation.ui

依附元件

Groovy

dependencies {
    implementation "androidx.navigation:navigation-ui-ktx:2.7.5"
}

Kotlin

dependencies {
    implementation("androidx.navigation:navigation-ui-ktx:2.7.5")
}

擴充功能函式

適用於 android.view.MenuItem
Boolean MenuItem.onNavDestinationSelected(navController: NavController)

嘗試前往與這個 MenuItem 關聯的 NavDestination

適用於 androidx.appcompat.app.AppCompatActivity
Unit AppCompatActivity.setupActionBarWithNavController(navController: NavController, drawerLayout: DrawerLayout?)

設定 AppCompatActivity.getSupportActionBar 傳回的 ActionBar,以便與 NavController 搭配使用。

Unit AppCompatActivity.setupActionBarWithNavController(navController: NavController, configuration: AppBarConfiguration = AppBarConfiguration(navController.graph))

設定 AppCompatActivity.getSupportActionBar 傳回的 ActionBar,以便與 NavController 搭配使用。

適用於 androidx.appcompat.widget.Toolbar
Unit Toolbar.setupWithNavController(navController: NavController, drawerLayout: DrawerLayout?)

設定工具列,以便與 NavController 搭配使用。

Unit Toolbar.setupWithNavController(navController: NavController, configuration: AppBarConfiguration = AppBarConfiguration(navController.graph))

設定工具列,以便與 NavController 搭配使用。

適用於 com.google.android.material.appbar.CollapsingToolbarLayout
Unit CollapsingToolbarLayout.setupWithNavController(toolbar: Toolbar, navController: NavController, drawerLayout: DrawerLayout?)

設定 CollapsingToolbarLayout工具列,以便與 NavController 搭配使用。

Unit CollapsingToolbarLayout.setupWithNavController(toolbar: Toolbar, navController: NavController, configuration: AppBarConfiguration = AppBarConfiguration(navController.graph))

設定 CollapsingToolbarLayout工具列,以便與 NavController 搭配使用。

適用於 com.google.android.material.bottomnavigation.BottomNavigationView
Unit BottomNavigationView.setupWithNavController(navController: NavController)

設定 BottomNavigationView,以便與 NavController 搭配使用。

適用於 com.google.android.material.navigation.NavigationView
Unit NavigationView.setupWithNavController(navController: NavController)

設定NavigationView,以便與 NavController 搭配使用。

適用於 NavController
Boolean NavController.navigateUp(drawerLayout: DrawerLayout?)

將「向上」按鈕的行為委派給指定的 NavController,以處理該按鈕。

Boolean NavController.navigateUp(appBarConfiguration: AppBarConfiguration)

將「向上」按鈕的行為委派給指定的 NavController,以處理該按鈕。

頂層函式

AppBarConfiguration AppBarConfiguration(navGraph: NavGraph, drawerLayout: DrawerLayout? = null, noinline fallbackOnNavigateUpListener: () -> Boolean = { false })

NavigationUI 方法的設定選項,與應用程式列模式的實作互動,例如 android.support.v7.widget.Toolbarandroid.support.design.widget.CollapsingToolbarLayoutandroid.support.v7.app.ActionBar

AppBarConfiguration AppBarConfiguration(topLevelMenu: Menu, drawerLayout: DrawerLayout? = null, noinline fallbackOnNavigateUpListener: () -> Boolean = { false })

NavigationUI 方法的設定選項,與應用程式列模式的實作互動,例如 android.support.v7.widget.Toolbarandroid.support.design.widget.CollapsingToolbarLayoutandroid.support.v7.app.ActionBar

AppBarConfiguration AppBarConfiguration(topLevelDestinationIds: Set<Int>, drawerLayout: DrawerLayout? = null, noinline fallbackOnNavigateUpListener: () -> Boolean = { false })

NavigationUI 方法的設定選項,與應用程式列模式的實作互動,例如 android.support.v7.widget.Toolbarandroid.support.design.widget.CollapsingToolbarLayoutandroid.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")
}

擴充功能函式

適用於工廠
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)

從這個 DataSource.Factory 建構 Flowable<PagedList>,來為 RxPagedListBuilder 提供便利。

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)

從這個 DataSource.Factory 建構 Flowable<PagedList>,來為 RxPagedListBuilder 提供便利。

LiveData<PagedList<Value>> DataSource.Factory<Key, Value>.toLiveData(config: PagedList.Config, initialLoadKey: Key? = null, boundaryCallback: PagedList.BoundaryCallback<Value>? = null, fetchExecutor: Executor = ArchTaskExecutor.getIOThreadExecutor())

從這個 DataSource.Factory 建構 LiveData<PagedList>,來為 LivePagedListBuilder 提供便利。

LiveData<PagedList<Value>> DataSource.Factory<Key, Value>.toLiveData(pageSize: Int, initialLoadKey: Key? = null, boundaryCallback: PagedList.BoundaryCallback<Value>? = null, fetchExecutor: Executor = ArchTaskExecutor.getIOThreadExecutor())

從這個 DataSource.Factory 建構 LiveData<PagedList>,來為 LivePagedListBuilder 提供便利。

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)

從這個 DataSource.Factory 建構 Observable<PagedList>,來為 RxPagedListBuilder 提供便利。

Observable<PagedList<Value>> DataSource.Factory<Key, Value>.toObservable(pageSize: Int, initialLoadKey: Key? = null, boundaryCallback: PagedList.BoundaryCallback<Value>? = null, fetchScheduler: Scheduler? = null, notifyScheduler: Scheduler? = null)

從這個 DataSource.Factory 建構 Observable<PagedList>,來為 RxPagedListBuilder 提供便利。

頂層函式

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.Swatch? Palette.get(target: Target)

從區塊面板傳回指定目標的選定樣本,或如果找不到樣本,則傳回「null」。

androidx.preference

依附元件

Groovy

dependencies {
    implementation "androidx.preference:preference-ktx:1.2.1"
}

Kotlin

dependencies {
    implementation("androidx.preference:preference-ktx:1.2.1")
}

擴充功能函式

適用於 PreferenceGroup
運算子 Boolean PreferenceGroup.contains(preference: Preference)

如果在這個偏好設定群組中找到 preference,則傳回「true」。

Unit PreferenceGroup.forEach(action: (preference: Preference) -> Unit)

對此偏好設定群組內的每個偏好設定執行指定動作。

Unit PreferenceGroup.forEachIndexed(action: (index: Int, preference: Preference) -> Unit)

對此設好設定群組內的每個偏好設定執行指定動作,並提供依序索引。

運算子 T? PreferenceGroup.get(key: CharSequence)

傳回具有 key 的偏好設定,或如果找不到具有 key 的偏好設定,則傳回「null」。

運算子 Preference PreferenceGroup.get(index: Int)

傳回 index 的偏好設定。

Boolean PreferenceGroup.isEmpty()

如果這個偏好群組不含任何偏好設定,則傳回「是」。

Boolean PreferenceGroup.isNotEmpty()

如果這個偏好設定群組包含一個或多個偏好設定,則傳回「是」。

運算子 MutableIterator<Preference> PreferenceGroup.iterator()

對這個偏好設定群組內的偏好設定傳回 MutableIterator

運算子 Unit PreferenceGroup.minusAssign(preference: Preference)

從這個偏好設定群組中移除 preference

運算子 Unit PreferenceGroup.plusAssign(preference: Preference)

preference 新增至這個偏好設定群組。

擴充功能屬性

適用於 PreferenceGroup
Sequence<Preference> PreferenceGroup.children()

對這個偏好設定群組內的偏好設定傳回序列

Int PreferenceGroup.size()

傳回這個偏好設定群組內的偏好設定數量。

androidx.room

依附元件

Groovy

dependencies {
    implementation "androidx.room:room-ktx:2.6.1"
}

Kotlin

dependencies {
    implementation("androidx.room:room-ktx:2.6.1")
}

擴充功能函式

適用於 RoomDatabase
suspend R RoomDatabase.withTransaction(block: suspend () -> R)

在資料庫交易中,呼叫指定的暫停「區塊」

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.4.0"
}

Kotlin

dependencies {
    implementation("androidx.sqlite:sqlite-ktx:2.4.0")
}

擴充功能函式

適用於 SupportSQLiteDatabase
T SupportSQLiteDatabase.transaction(exclusive: Boolean = true, body: SupportSQLiteDatabase.() -> T)

在交易中執行主體,如果執行完畢,且沒有例外狀況,則標記為成功。

androidx.work

依附元件

擴充功能函式

適用於 com.google.common.util.concurrent.ListenableFuture
suspend R ListenableFuture<R>.await()

等候 ListenableFuture 完成,而不會封鎖執行緒。

適用於作業
suspend Operation.State.SUCCESS! Operation.await()

等候作業,而不會封鎖執行緒。

適用於資料
Boolean Data.hasKeyWithValueOfType(key: String)

如果資料執行個體的值與具有預期類型 T 的指定相符,則傳回「是」。

適用於建構工具
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?>)

將配對清單轉換成資料物件。

androidx.work.testing

依附元件

Groovy

dependencies {
    implementation "androidx.work:work-testing:2.9.0"
}

Kotlin

dependencies {
    implementation("androidx.work:work-testing:2.9.0")
}

頂層函式

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 片段,來傳回結果。

適用於 com.google.android.play.core.splitinstall.SplitInstallManager
suspend Unit SplitInstallManager.requestCancelInstall(sessionId: Int)

暫停 SplitInstallManager.cancelInstall 的版本

suspend Unit SplitInstallManager.requestDeferredInstall(moduleNames: List<String>)

暫停 SplitInstallManager.deferredInstall 的版本

suspend Unit SplitInstallManager.requestDeferredLanguageInstall(languages: List<Locale>)

暫停 SplitInstallManager.deferredLanguageInstall 的版本

suspend Unit SplitInstallManager.requestDeferredLanguageUninstall(languages: List<Locale>)

暫停 SplitInstallManager.deferredLanguageUninstall 的版本

suspend Unit SplitInstallManager.requestDeferredUninstall(moduleNames: List<String>)

暫停 SplitInstallManager.deferredUninstall 的版本

suspend Int SplitInstallManager.requestInstall(modules: List<String> = listOf(), languages: List<String> = listOf())

啟動所要求的模組/語言的安裝作業。

Flow<SplitInstallSessionState> SplitInstallManager.requestProgressFlow()

建立並傳回緩衝的資料流,可為進行中的分割安裝作業傳送所有進度事件。

suspend SplitInstallSessionState SplitInstallManager.requestSessionState(sessionId: Int)

暫停 SplitInstallManager.getSessionState 的版本

suspend List<SplitInstallSessionState> SplitInstallManager.requestSessionStates()

暫停 SplitInstallManager.getSessionStates 的版本

Boolean SplitInstallManager.startConfirmationDialogForResult(sessionState: SplitInstallSessionState, fragment: Fragment, requestCode: Int)

SplitInstallManager.startConfirmationDialogForResult 的一個版本,可接受 AndroidX 片段,來傳回結果。

擴充功能屬性

適用於 com.google.android.play.core.appupdate.AppUpdateInfo
Int AppUpdateInfo.installStatus()

傳回更新的進度狀態。

Boolean AppUpdateInfo.isFlexibleUpdateAllowed()

如果允許靈活的更新,則傳回「true」。

Boolean AppUpdateInfo.isImmediateUpdateAllowed()

如果允許立即更新,則傳回「true」。

適用於 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 的便利函式。