資訊一覽互通性

在某些情況下,您可能想要使用 XML 和 RemoteViews 來提供檢視畫面。您可能已經在沒有 Glance 的情況下實作某項功能,或是這項功能尚未提供,或是無法在目前的 Glance API 中使用。針對這些情況,Glance 提供 AndroidRemoteViews 互通性 API。

AndroidRemoteViews 可組合項可讓 RemoteViews 與其他可組合項一起放置:

val packageName = LocalContext.current.packageName
Column(modifier = GlanceModifier.fillMaxSize()) {
    Text("Isn't that cool?")
    AndroidRemoteViews(RemoteViews(packageName, R.layout.example_layout))
}

建立並定義 RemoteViews,方法與使用 Glance 相同,然後直接將其做為參數傳遞。

此外,您還可以為可組合項建立 RemoteViews 容器:

AndroidRemoteViews(
    remoteViews = RemoteViews(packageName, R.layout.my_container_view),
    containerViewId = R.id.example_view
) {
    Column(modifier = GlanceModifier.fillMaxSize()) {
        Text("My title")
        Text("Maybe a long content...")
    }
}

在這種情況下,包含「容器」的版面配置會以定義的 ID 傳遞。此容器必須是 ViewGroup,因為會用來放置已定義的內容。