display-glasses-with-jetpack-compose-glimmer
Skill file xr/display-glasses-with-jetpack-compose-glimmer/SKILL.md in android/skills. Read the publisher’s upstream source.
Description awaits a fresh source check.
Try your first task
display-glasses-with-jetpack-compose-glimmer
Start a fresh conversation. Replace the highlighted placeholders.
Use display-glasses-with-jetpack-compose-glimmer to Create a dedicated projected Glasses Activity for [Android app] using GlimmerTheme, Google Sans Flex typography, and a pure-black root background; ensure compileSdk is at least 37 and do not use Material components.
Required inputs
- [Android app]
User-approved starter prompt based on a pinned source version; check current skill requirements before running. Task evidence ↗
SKILL.md
name: display-glasses-with-jetpack-compose-glimmerdescription: Provides guidelines for developing projected Android XR apps for display glasses using the Jetpack Compose Glimmer UI toolkit. Covers Glimmer design principles, workflows, and interaction models for the glasses form factor. Use this skill to build an Android XR Augmented Experience app with Jetpack Compose Glimmer. Don't use for audio-only AI glasses without a display, non-glasses Android XR headsets (spatial panels or 3D volumes with Jetpack Compose for XR), or phone and tablet Material 3 UIs.license: Complete terms in LICENSE.txtmetadata: author: Google LLC last-updated: '2026-11-13' keywords: - Jetpack Compose Glimmer - display glasses - Projected Activity - GlimmerTheme - Additive Display - Android XR - Augmented ExperiencesGlossary
| Term | Definition |
|---|---|
| Intelligent eyewear | Hands-free eyewear with speakers, camera, and microphone (audio-only or display). |
| Display glasses | Eyewear with a private in-lens display for glanceable visuals and audio. |
| Jetpack Compose Glimmer | Compose UI toolkit with components, theming, and focus for display glasses. |
| Projected activity | Host phone Activity whose UI and input are projected to connected eyewear. |
| Projected device | XR eyewear device connected to an Android host phone projecting content. |
| GlimmerTheme | Root styling provider for GlimmerColors, GlimmerTypography, GlimmerShapes. |
| Additive display | Display where black (#000000) renders 100% transparent by adding light. |
| Augmented experiences | Lightweight, additive Android XR experiences for users on the go. |
Prerequisites and core constraints
- Target
compileSdk37 or higher (compileSdk = 37orcompileSdk { version = release(37) }). - When adding dependencies, follow Create your first activity for intelligent
eyewear and Declaring Jetpack Compose Glimmer Dependencies (check
gradle/libs.versions.tomlfirst; never guess1.0.0-alpha01):androidx.xr.glimmer:glimmer(1.0.0-alpha21+orlibs.androidx.glimmer)androidx.xr.glimmer:glimmer-google-fonts(1.0.0-alpha21+orlibs.androidx.glimmer.google.fonts)androidx.xr.projected:projected(1.0.0-alpha13+orlibs.androidx.xr.projectedorlibs.androidx.projected)
- Don't : Use
MaterialTheme, Material 3 (androidx.compose.material3.*), or Material elevation or shadow modifiers inside Glimmer UI. - Do : Use
GlimmerTheme, Glimmer components (androidx.xr.glimmer.*),DepthEffectLevels, andcreateGoogleSansFlexTypography()(androidx.xr.glimmer.googlefonts). Minimum text size is 18sp; avoid Thin or Hairline weights.
1. Set up dependencies
-
Set up projected activity : Follow Create your first activity for intelligent eyewear and projectedcontext-source.md. Set
android:exported="true"andandroid:requiredDisplayCategorytoandroid.hardware.display.category.XR_PROJECTEDinAndroidManifest.xml:<activity android:name="com.example.xr.projected.ProjectedMainActivity" android:exported="true" android:requiredDisplayCategory="android.hardware.display.category.XR_PROJECTED"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.XR_PROJECTED_LAUNCHER"/> </intent-filter> </activity> -
Mobile app integration : Add a
Text("Launch on Glasses")button on the host phone. ObserveProjectedContext.isProjectedDeviceConnected(context, coroutineContext)usingcollectAsStateWithLifecycle(initialValue = false)to setenabled(so it is disabled when disconnected) and launchGlassesMainActivitywithProjectedContext.createProjectedActivityOptions(context).toBundle():val options = ProjectedContext.createProjectedActivityOptions(context) val intent = Intent(context, ProjectedMainActivity::class.java) context.startActivity(intent, options.toBundle()) -
Theming, initial focus, and black background : Follow glimmersansflextypography-source.md. In
onCreate(with@OptIn(ExperimentalComposeUiApi::class)), setComposeUiFlags.isInitialFocusOnFocusableAvailable = true(androidx.compose.ui.ComposeUiFlags), wrap UI inGlimmerTheme(typography = createGoogleSansFlexTypography()), and applyModifier.background(Color.Black)(orGlimmerTheme.colors.background) to the root container:@OptIn(ExperimentalProjectedApi::class) class ProjectedMainActivity : ComponentActivity() { private var displayController: ProjectedDisplayController? = null private var isVisualUiSupported by mutableStateOf(false) private var areVisualsOn by mutableStateOf(true) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) lifecycle.addObserver(object : DefaultLifecycleObserver { override fun onDestroy(owner: LifecycleOwner) { displayController?.close() displayController = null } }) initializeGlassesFeatures() setContent { GlimmerTheme { HomeScreen( areVisualsOn = areVisualsOn, isVisualUiSupported = isVisualUiSupported, onClose = { finish() } ) } } } private fun initializeGlassesFeatures() { lifecycleScope.launch { // Check device capabilities val projectedDeviceController = ProjectedDeviceController.create(this@ProjectedMainActivity) isVisualUiSupported = projectedDeviceController.capabilities.contains(CAPABILITY_VISUAL_UI) val controller = ProjectedDisplayController.create(this@ProjectedMainActivity) displayController = controller val observer = GlassesLifecycleObserver( context = this@ProjectedMainActivity, controller = controller, onVisualsChanged = { visualsOn -> areVisualsOn = visualsOn } ) lifecycle.addObserver(observer) } } }
2. Minimize UI and map input controls
-
Bottom-align UI (
Alignment.BottomCenter), show one primary piece of info at a time (VerticalStack), and avoid multiple simultaneous cards. -
Color contrast : Follow material-hct-source.md to keep at least a 70% HCT tone difference between foreground and background (
#000000). -
Focus and 1D input : Avoid nesting scrolling controls; use System Back to dismiss views. For focus (
androidx.compose.foundation.focusGroupandandroidx.compose.ui.focus.*) and hardware input, follow Focus in Jetpack Compose Glimmer and Hardware Controls for display glasses:@Composable fun FocusSample(initialFocus: FocusRequester) { Box( modifier = Modifier.focusProperties { onEnter = { initialFocus.requestFocus() cancelFocusChange() } } .focusGroup() ) { Button(onClick = {}) { Text("First Button") } } }
3. Build with Jetpack Compose Glimmer
Implementing Glimmer styles
Follow glimmertheme-source.md when using GlimmerTheme.
| Category | Token | Value / Role |
|---|---|---|
| Color | primary / secondary | #9BBFFF / #4C88E9 (Focal colors) |
| Color | positive / negative | #7AD48F (Confirmation) / #F57082 (Alert) |
| Color | background / surface | #000000 (Transparent) / #262626 (GlimmerTheme.colors.surface, SurfaceDefaults.border) |
| Shape | large (Standard) / small | RoundedCornerShape(36.dp) / RoundedCornerShape(12.dp) |
Typography scale (Google Sans Flex) and depth levels
Pass FontVariation.Settings(FontVariation.Setting("ROND", 100f), FontVariation.width(100f), FontVariation.opticalSizing(9.sp), FontVariation.weight(...)) to createGoogleSansFlexTypography
(titleLargeVariationSettings, bodyMediumVariationSettings,
captionVariationSettings, and other role settings):
| Style | Size / Line-Height | Weight |
|---|---|---|
| Title Large / Medium / Small | 30/36.sp, 24/32.sp, 20/28.sp | 725 |
| Body Large / Medium / Small | 30/36.sp, 24/32.sp, 20/28.sp | 520 |
| Caption | 18.sp / 28.sp | 650 |
Follow deptheffect-source.md and deptheffectlevels-source.md for
DepthEffect and DepthEffectLevels: use
GlimmerTheme.depthEffectLevels.level1 for resting state and level2 for
focused state (using SurfaceDepthEffect(depthEffect = level1, focusedDepthEffect = level2) on Modifier.surface or Modifier.depthEffect):
@Composable
fun DepthEffectLevelsSample() {
val levels = GlimmerTheme.depthEffectLevels
Box(contentAlignment = Alignment.Center) {
DepthBox("Level 1", levels.level1)
DepthBox("Level 2", levels.level2)
DepthBox("Level 3", levels.level3)
DepthBox("Level 4", levels.level4)
DepthBox("Level 5", levels.level5)
}
}
@Composable
private fun DepthBox(name: String, depthEffect: DepthEffect) {
val interactionSource = remember { MutableInteractionSource() }
Box(
modifier = Modifier
.size(100.dp)
.surface(
interactionSource = interactionSource,
depthEffect = SurfaceDepthEffect(
depthEffect = depthEffect,
focusedDepthEffect = depthEffect
)
),
contentAlignment = Alignment.Center
) {
Text(name)
}
}
Implementing Jetpack Compose Glimmer components
Cards, ActionCards, ImageCards, and ButtonGroups
Never embed Card (androidx.xr.glimmer.Card) in ListItem. Follow Jetpack
Compose Glimmer: Cards, card-source.md, and
card-samples-source.md.
-
Clickable vs. non-clickable : Pass
onClick = { ... }if the whole card is a trigger; omitonClickif informational and control focus usingfocusable: Boolean(such asCard(focusable = false)). -
Single primary action (
ActionCard) : Useandroidx.xr.glimmer.ActionCardwhen anchoring a primary action button to the bottom of a card:ActionCard( action = { Button(onClick = {}, trailingIcon = { Icon(FavoriteIcon, "Localized description") }) { Text("Send") } } ) { Text("This is a card with a title, leading icon, header image, and action") } -
Multiple actions (
CardandButtonGroup) : Useandroidx.xr.glimmer.ButtonGroup(rememberButtonGroupState). Never nestButtonGroupinsideCard { ... }. PlaceCard(focusable = false)aboveButtonGroupas a sibling in aColumnto avoid focus contention:ButtonGroup(modifier = Modifier.fillMaxWidth()) { Button(onClick = {}) { Text("Button 1") } Button(onClick = {}) { Text("Button 2") } Button(onClick = {}) { Text("Button 3") } Button(onClick = {}) { Text("Button 4") } Button(onClick = {}) { Text("Button 5") } }val scope = rememberCoroutineScope() val state = rememberButtonGroupState() ButtonGroup(modifier = Modifier.fillMaxWidth(), state = state) { Button(onClick = { scope.launch { state.animateScrollToItem(1) } }) { Text("Select last item") } Button(onClick = { scope.launch { state.animateScrollToItem(0) } }) { Text("Select first item") } } -
Image cards : Use
ImageCard,LeadingImageCard, orTrailingImageCard(image = { ... },title,subtitle,leadingIcon,trailingIcon) withContentScale.Crop,Outline(CardDefaults.shape), andmaxLines = 10on long bodyText:ImageCard( image = { Image( painter = myHeaderImage, contentDescription = "Header image", contentScale = ContentScale.FillWidth ) }, title = { Text("Card Title", style = GlimmerTheme.typography.titleMedium) }, subtitle = { Text("Sub-heading text", style = GlimmerTheme.typography.titleSmall) }, leadingIcon = { Icon(FavoriteIcon, contentDescription = "Favorite") }, ) { Text( "This is the main body content of the card, utilizing theme-tokens for consistent styling.", style = GlimmerTheme.typography.bodyMedium ) }
Buttons and ToggleButtons
Follow Jetpack Compose Glimmer: Buttons, button-source.md, and
button-samples-source.md. Use Button(onClick, buttonSize = ButtonSize.Large, color = baseColor, focusedColor = ButtonDefaults.focusedColor(baseColor)) (top-level parameters on Button,
never ButtonDefaults.colors), IconButton for stateless icon
triggers, and always use ToggleButton(checked, onCheckedChange, leadingIcon)
or IconToggleButton(checked, onCheckedChange) (never stateful IconButton)
for toggle or media playback controls:
Button(
onClick = {},
focusedColor = brandColor,
) {
Text("Focus Color Button")
}
@Composable
fun ToggleButtonWithLeadingIconSample() {
var checked by remember { mutableStateOf(false) }
ToggleButton(
checked = checked,
leadingIcon = {
Icon(
if (checked) FavoriteIcon else OutlinedFavoriteIcon,
contentDescription = "Toggle favorite"
)
},
onCheckedChange = { checked = it }
) {
Text(if (checked) "On" else "Off")
}
}
var checked by remember { mutableStateOf(false) }
val additionalColors =
IconToggleButtonDefaults.colors(checkedBackgroundColor = Color(0xFF80B799))
IconToggleButton(
checked = checked,
onCheckedChange = { checked = it },
colors = additionalColors
) {
Icon(
if (checked) FavoriteIcon else OutlinedFavoriteIcon,
contentDescription = "Toggle favorite"
)
}
Title chips
TitleChip (androidx.xr.glimmer.TitleChip) is a non-interactive pill header
(three words or fewer, single line). Follow Jetpack Compose Glimmer: Title
Chips, titlechip-source.md, and titlechip-samples-source.md.
When placing a standalone TitleChip above a Card or ActionCard, center it
and space it with TitleChipDefaults.associatedContentSpacing:
@Composable
fun TitleChipWithCardSample() {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
TitleChip { Text("Title Chip") }
Spacer(Modifier.height(TitleChipDefaults.associatedContentSpacing))
Card(
title = { Text("Title") },
subtitle = { Text("Subtitle") },
leadingIcon = { Icon(FavoriteIcon, "Localized description") },
) {
Text("Card Content")
}
}
}
Icons
Follow Jetpack Compose Glimmer: Icons, icon-source.md, iconbutton-source.md, and iconsizes-source.md.
-
Sizing and contrast : Pass
Modifier.size(GlimmerTheme.iconSizes.small),GlimmerTheme.iconSizes.medium, orGlimmerTheme.iconSizes.largetoIconwhenever a small, medium, or large icon is needed (including inside card icon slots). Never useColor.Blackor saturated error tints; useColor.Unspecifiedfor multicolor vectors (tint = nullonPainter). Use Material Symbols (600 weight, Rounded, Unfilled), or build vectors withImageVector.BuilderorpainterResourceifmaterial-icons-*isn't inapp/build.gradle.kts:@Composable fun SizedIconSample() { Icon( FavoriteIcon, contentDescription = "Localized description", modifier = Modifier.size(GlimmerTheme.iconSizes.large), ) }
Lists
Follow list-source.md, listitem-source.md, and liststate-source.md.
-
Always use
GlimmerLazyColumn: ImportGlimmerLazyColumn,rememberGlimmerLazyListState, anditemsfromandroidx.xr.glimmer.list(never foundationLazyColumn). UselistState.scrollToItem(0)oranimateScrollToItem(0)to scroll to top. -
Integrated title, spacing, and rows : Pass
title = { TitleChip { Text("...") } }directly onGlimmerLazyColumn, explicitly setverticalArrangement = Arrangement.spacedBy(20.dp), and render rows withandroidx.xr.glimmer.ListItem(onClick = { ... }, supportingLabel = { Text(...) }) { Text(...) }(never nestCardinListItem):@Composable fun GlimmerLazyColumnWithTitleChipSample() { val ingredientItems = listOf("Milk", "Flour", "Egg", "Salt", "Apples", "Butter", "Vanilla", "Sugar", "Cinnamon") GlimmerLazyColumn(title = { TitleChip { Text("Ingredients") } }) { items(ingredientItems) { text -> ListItem { Text(text) } } } }
Stacks
Use VerticalStack (androidx.xr.glimmer.stack.VerticalStack) for
heterogeneous cards one at a time (never with TitleChip). Follow
stack-source.md, stackstate-source.md, and
stackitemscope-source.md. Align to Alignment.BottomCenter, set height to
66.dp taller than the tallest card (Modifier.height(maxCardHeight + 66.dp)), and apply Modifier.itemDecoration(CardDefaults.shape) to each item's
Card:
@Composable
fun VerticalStackSample() {
VerticalStack {
item {
Card { Text("Top Card") }
}
item {
Card { Text("Second Card") }
}
item {
Card { Text("Third Card") }
}
}
}
Horizontal pagers and animated text
Use GlimmerHorizontalPager
(androidx.xr.glimmer.pager.GlimmerHorizontalPager) with
rememberGlimmerPagerState(pageCount = { ... }), pageSpacing, and
pageIndicator = { GlimmerHorizontalPagerDefaults.PageIndicator(state, selectedIndicatorColor = GlimmerTheme.colors.primary, unselectedIndicatorColor = GlimmerTheme.colors.primary.copy(alpha = GlimmerHorizontalPagerDefaults.UnselectedIndicatorAlpha)) } (never foundation
HorizontalPager). Follow Jetpack Compose Glimmer: Pager. Use
pagerState.animateScrollToPage in a coroutine for programmatic scroll, and
configure Glimmer Text (androidx.xr.glimmer.Text, never Material
Text) with style = LocalTextStyle.current.copy(textMotion = TextMotion.Animated):
// Hoist the pager state, specifying the total page count with a lambda.
val pagerState = rememberGlimmerPagerState(pageCount = { 10 })
GlimmerHorizontalPager(
state = pagerState,
modifier = Modifier.fillMaxSize(),
) { page ->
// Use Glimmer components like Card and Text for optimized glasses styling.
Card(modifier = Modifier.fillMaxWidth()) {
Text(
text = "Page: $page",
// Recommended: use TextMotion.Animated for smooth transitions in a pager.
style = LocalTextStyle.current.copy(textMotion = TextMotion.Animated),
)
}
}
GlimmerHorizontalPager(
state = pagerState,
modifier = Modifier.fillMaxSize(),
// Use a page numbers instead of the default dot-indicator
pageIndicator = {
Text(
text = "${pagerState.currentPage + 1} / ${pagerState.pageCount}",
style = LocalTextStyle.current.copy(textMotion = TextMotion.Animated),
)
}
)
AlertDialogs and custom surfaces
-
AlertDialog: Useandroidx.xr.glimmer.AlertDialog(neverandroid.appor MaterialAlertDialog) withonDismissRequest,confirmButton,dismissButton,icon,title, andtextusing GlimmerButton,Icon, andText:var showDialog by remember { mutableStateOf(true) } if (showDialog) { AlertDialog( onDismissRequest = { showDialog = false }, confirmButton = { Button(onClick = { /* confirm action */ }) { Text("Confirm") } }, dismissButton = { Button(onClick = { showDialog = false }) { Text("Dismiss") } }, icon = { Icon(imageVector = FavoriteIcon, contentDescription = "Alert icon") }, title = { Text("Title") }, text = { Text("This is an alert dialog with options to confirm or dismiss.") }, ) }var showDialog by remember { mutableStateOf(true) } if (showDialog) { AlertDialog( onDismissRequest = { showDialog = false }, confirmButton = { Button(onClick = { showDialog = false }) { Text("OK") } }, icon = { Icon( imageVector = OutlinedFavoriteIcon, contentDescription = "Favorite icon", ) }, title = { Text("Title") }, text = { Text("This is an alert dialog with only an option to dismiss.") }, ) } -
Modifier.surface: Follow surface-source.md. Share oneremember { MutableInteractionSource() }betweenModifier.surface(enabled = true, shape = GlimmerTheme.shapes.large, color = GlimmerTheme.colors.surface, depthEffect = ..., interactionSource = interactionSource)and.focusable(interactionSource = interactionSource)or.clickable(interactionSource = interactionSource, indication = null, ...), chaining.surface(...)before.focusable(...)or.clickable(...):@Composable fun FocusableSurfaceSample() { val interactionSource = remember { MutableInteractionSource() } Box( modifier = Modifier .size(100.dp) .surface(interactionSource = interactionSource) .focusable(interactionSource = interactionSource), contentAlignment = Alignment.Center ) { Text("Focusable") } } @Composable fun ClickableSurfaceSample() { val interactionSource = remember { MutableInteractionSource() } Box( modifier = Modifier .size(100.dp) .surface(interactionSource = interactionSource) .focusable(interactionSource = interactionSource) .clickable( interactionSource = interactionSource, indication = null ) { /* Handle click action */ }, contentAlignment = Alignment.Center ) { Text("Clickable") } }
Voice input indicator and indirect pointer gestures
Follow Jetpack Compose Glimmer: Voice Input Indicator and Jetpack Compose Glimmer: Indirect Pointer.
-
VoiceInputIndicatorandContainedVoiceInputIndicator: NormalizeSpeechRecognizerrmsdBvalues into0.0f..1.0fusing.coerceIn(0f, 1f):// Example state variable to hold the normalized level (0.0 to 1.0) // that the VoiceInputIndicator component expects. val audioLevel = MutableStateFlow(0f) // Initialize the Android SpeechRecognizer val speechRecognizer = SpeechRecognizer.createSpeechRecognizer(context) // Listener to capture speech events and audio level changes val listener = object : RecognitionListener { override fun onRmsChanged(rmsdB: Float) { // Normalize raw dB level to a 0.0-1.0 range. // Android SpeechRecognizer's rmsdB typically ranges from 0 to ~10. audioLevel.value = ((rmsdB - 1f) / 9f).coerceIn(0f, 1f) } // ... Implement other required RecognitionListener methods ... override fun onReadyForSpeech(params: Bundle?) {} override fun onBeginningOfSpeech() {} override fun onEndOfSpeech() {} override fun onError(error: Int) {} override fun onResults(results: Bundle?) {} override fun onPartialResults(partialResults: Bundle?) {} override fun onEvent(eventType: Int, params: Bundle?) {} override fun onBufferReceived(buffer: ByteArray?) {} } // Attach the listener to the recognizer speechRecognizer.setRecognitionListener(listener) // Create an intent to specify the recognition model and behavior val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply { putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM) } // Begin listening for audio input speechRecognizer.startListening(intent)@Composable fun VoiceInputExample(modifier: Modifier) { // Collect the flow as Compose State so the UI reacts to changes in real-time. val currentLevel by audioLevel.collectAsState() VoiceInputIndicator( // The VoiceInputIndicator component provides a visual "pulse" or indicator // that changes based on the 'level' lambda, which returns a Float between 0.0 and 1.0. level = { currentLevel }, modifier = modifier ) } -
Modifier.onIndirectPointerGesture: Applyandroidx.xr.glimmer.onIndirectPointerGesture(onClick,onSwipeForward,onSwipeBackward) to a container made focusable (focusTarget()orfocusable()):@Composable fun OnIndirectPointerGestureSample() { var lastGesture by remember { mutableStateOf("None") } Box( modifier = Modifier.fillMaxSize() .onIndirectPointerGesture( enabled = true, onSwipeForward = { lastGesture = "Forward" }, onSwipeBackward = { lastGesture = "Backward" }, onClick = { lastGesture = "Click" }, ) .focusTarget(), contentAlignment = Alignment.Center, ) { Text("Last Gesture: $lastGesture") } }