Agent Skills › android/skills › glance-canonical-layouts

glance-canonical-layouts

GitHub

基于Jetpack Glance实现Android主屏幕小部件,支持清单、网格等标准布局。通过复制参考文件并配置依赖和Manifest完成开发。

system/glance-canonical-layouts/SKILL.md android/skills

Trigger Scenarios

创建Android桌面小部件 使用Jetpack Glance Canonical Layouts

Install

npx skills add android/skills --skill glance-canonical-layouts -g -y
More Options

Non-standard path

npx skills add https://github.com/android/skills/tree/main/system/glance-canonical-layouts -g -y

Use without installing

npx skills use android/skills@glance-canonical-layouts

指定 Agent (Claude Code)

npx skills add android/skills --skill glance-canonical-layouts -a claude-code -g -y

安装 repo 全部 skill

npx skills add android/skills --all -g -y

预览 repo 内 skill

npx skills add android/skills --list

SKILL.md

Frontmatter
{
    "name": "glance-canonical-layouts",
    "license": "Complete terms in LICENSE.txt",
    "metadata": {
        "author": "Google LLC",
        "keywords": [
            "android",
            "glance",
            "widgets",
            "appwidget",
            "canonical-layouts",
            "platform-samples",
            "action-list",
            "check-list",
            "image-grid",
            "image-text-list",
            "snap-scrolling",
            "full-bleed",
            "expressive-toolbar",
            "search-toolbar",
            "standard-toolbar"
        ],
        "last-updated": "2026-10-14"
    },
    "description": "Use this skill to create home screen widgets using Jetpack Glance Canonical Layouts from the Android Platform Samples project, or when asked to implement standard widget layout patterns (including Check List, Image Grid, Snap Scrolling, and Standard Toolbar)."
}

To implement a widget Canonical Layout that follows the recommended design patterns:

  1. The project MUST use Jetpack Glance.
  2. You MUST locate the requested layout from the list under Canonical Layout Reference Files.
  3. Copy the layout reference files into your project's target app module (e.g., src/main/java/ and src/main/res/) in one step to implement the exact design and reduce the number of tool calls.
  4. You MUST set override val sizeMode: SizeMode = SizeMode.Exact in the widget provider class.
  5. Validate that your project compiles, updating sample package declarations, import paths, and class names to match the target app's package name.
  6. Clean your project's widget code, removing unused classes (for example, unused buttons).
  7. You MUST register the widget receiver in AndroidManifest.xml inside <application> after <activity>, ensuring android:resource="@xml/..." matches the filename of the copied Widget Info XML. Otherwise, the widget won't appear in the widget picker:

<receiver android:name=".glance.MyReceiver"
    android:exported="true">
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    </intent-filter>
    <meta-data
        android:name="android.appwidget.provider"
        android:resource="@xml/my_app_widget_info" />
</receiver>

Dependencies

Add Jetpack Glance dependencies to the app module's build.gradle.kts (dependencies block):

  • androidx.glance:glance-appwidget:1.2.0 or higher
  • androidx.glance:glance-material3:1.2.0 or higher
  • androidx.glance:glance-appwidget-preview:1.2.0 or higher
  • androidx.glance:glance-preview:1.2.0 or higher

Use version 1.3.0-alpha02 or higher with compileSdk = 37 and Android Gradle Plugin (AGP) 9.1.0 or higher (for example, agp = "9.1.0" in gradle/libs.versions.toml) when implementing Snap Scrolling.

If copying sample data repositories that load bitmaps with Coil (such as FakeImageGridDataRepository.kt, FakeImageTextListDataRepository.kt, or FakeTextWithImageRepository.kt), also add an image loading library dependency such as io.coil-kt:coil (e.g., implementation("io.coil-kt:coil:2.7.0")) if one doesn't already exist.

Canonical layout reference files

Action list layout (action_list)

Check list layout (check_list)

Expressive toolbar layout (expressive_toolbar)

Image grid layout (image_grid)

Image text list layout (image_text_list)

Long text layout (long_text)

Search toolbar layout (search_toolbar)

Full-bleed image layout and snap scrolling (snap_scrolling)

Standard toolbar layout (standard_toolbar)

Text with image layout (text_with_image)

Troubleshooting

  1. Background Colors : Use GlanceModifier.background(Color) directly for solid background colors rather than ColorProvider, otherwise the background will be transparent.
  2. When using ColorProvider (outside of the background), avoid import errors :
    1. Import type: import androidx.glance.unit.ColorProvider
    2. Use fully qualified creator: androidx.glance.color.ColorProvider(dayColor, nightColor)

Checklist

  • [ ] Did you register the widget in the AndroidManifest?
  • [ ] Did you copy the corresponding Widget Info XML file and leave the given values including minWidth, minHeight, and minResizeHeight unchanged?
  • [ ] Did you use the given Glance Theme color values from the corresponding Layout Composable file?
  • [ ] Did you use dimension resource references for android:minWidth and android:minHeight in appwidget-provider XML definitions?
  • [ ] Did you override val sizeMode: SizeMode = SizeMode.Exact in the widget provider class?

Version History

  • 5bda39f Current 2026-10-19 06:12

Same Skill Collection

build-system/agp/agp-9-upgrade/SKILL.md
camera/camerax/SKILL.md
device-ai/appfunctions/SKILL.md
device-ai/ml-kit-genai-prompt-api/SKILL.md
devtools/android-cli/SKILL.md
identity/restore-credentials/SKILL.md
identity/verified-email/SKILL.md
jetpack-compose/jetpack-compose-performance/SKILL.md
jetpack-compose/migration/migrate-xml-views-to-jetpack-compose/SKILL.md
jetpack-compose/theming/styles/SKILL.md
media/media3-cast-integration/SKILL.md
navigation/navigation-3/SKILL.md
navigation/navigation-event/SKILL.md
performance/r8-analyzer/SKILL.md
play/engage-sdk-integration/SKILL.md
play/play-billing-library-version-upgrade/SKILL.md
play/play-policy-insights/SKILL.md
profilers/perfetto-sql/SKILL.md
profilers/perfetto-trace-analysis/SKILL.md
security/android-intent-security/SKILL.md
security/android-permissions-security/SKILL.md
system/edge-to-edge/SKILL.md
testing/testing-setup/SKILL.md
wear/wear-compose-m3/SKILL.md
xr/display-glasses-with-jetpack-compose-glimmer/SKILL.md
cars/android-for-cars-parked-apps/SKILL.md
device-ai/litert/litert-runtime/SKILL.md
jetpack-compose/adaptive/SKILL.md
profilers/android-profiler/SKILL.md
tv/leanback-to-compose-tv-migration/SKILL.md
wear/wear-widgets/SKILL.md

Metadata

Files
0
Version
5bda39f
Hash
d18b93f3
Indexed
2026-10-19 06:12

홈 - 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-10-25 04:22
浙ICP备14020137号-1