跳到正文
Skillpedia
移动应用10k · #11936

glance-canonical-layouts

它能做什么

这个技能会把 Android 示例项目中的标准小组件布局复制到你的应用中,使用 Jetpack Glance。布局包括清单、图片网格、整页滑动和标准工具栏。适合开发桌面小组件的 Android 开发者。

适用场景

  • ✓你想为桌面添加带清单或图片网格的小组件的时候。
  • ✓你的 Android 应用需要标准小组件工具栏或整页滑动布局的时候。
  • ✓新小组件没有出现在小组件选择器中,需要检查其注册情况的时候。

技能链接

https://github.com/android/skills/blob/main/system/glance-canonical-layouts/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/android/skills/blob/main/system/glance-canonical-layouts/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请帮我用标准的 Glance 布局为我的 Android 应用添加一个清单小组件。”

每周 5 个新技能,1 分钟读完。

工作原理

这个技能会把所选布局的参考文件复制到你的应用中,并更新包名和导入语句。它会删除不用的部分,并在清单文件中注册小组件接收器,使其出现在选择器中。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

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:
<br />
<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>
<br />

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)

常见问题

为什么我的小组件没有出现在选择器中?

接收器必须在清单文件中注册,并配有对应的小组件信息文件,这个技能会进行检查。

它需要 Jetpack Glance 吗?

需要。项目必须使用 Jetpack Glance 才能使用这些布局。

它使用哪种尺寸模式?

这个技能会在小组件提供者类中把尺寸模式设为精确模式。

详情

作者的原始描述

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).

repo: android/skills

热度

GitHub 星标
10k
排名
#11936
许可证
Apache-2.0
更新时间
2026/10/29

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能