On this page
Building UI from a design mockup is repetitive: rows, columns, paddings, typography. AI is good at that first draft. It's weaker at the things that make UI production-quality: correct state ownership, your design tokens, accessibility, and behaviour on different screen sizes.
The workflow
A prompt that produces better drafts
Create a Jetpack Compose screen matching the attached design.
Constraints:
- Stateless composable `OrderSummaryContent(state: OrderSummaryUiState, onPay: () -> Unit, onEditAddress: () -> Unit, modifier: Modifier = Modifier)`.
- Define `OrderSummaryUiState` as an immutable data class with only the fields the UI needs.
- Use MaterialTheme colorScheme, typography and shapes only (no hard-coded colors or font sizes).
- Use stringResource placeholders for user-facing text (list the string keys at the end).
- Content descriptions for icons; touch targets at least 48dp.
- Use LazyColumn for the item list with stable keys.
- Add @Preview for light, dark and fontScale 1.5 with realistic sample data.
Don't add ViewModels, navigation or networking.Typical fixes after generation
@Composable
fun OrderSummary() {
var items by remember { mutableStateOf(listOf("Mug", "T-shirt")) } // โ state owned here, fake data
Column(Modifier.padding(16.dp).background(Color(0xFFF5F5F5))) { // โ hard-coded color
Text("Order Summary", fontSize = 22.sp, fontWeight = FontWeight.Bold) // โ hard-coded typography
items.forEach { Text(it) } // โ not lazy, no keys
Icon(Icons.Default.Edit, contentDescription = null, // โ no description, tiny target
modifier = Modifier.size(16.dp).clickable { })
Button(onClick = { }) { Text("Pay โน1,298") } // โ action not hoisted
}
}data class OrderSummaryUiState(val items: List<OrderLineUi>, val totalText: String, val address: String)
data class OrderLineUi(val id: String, val name: String, val priceText: String)
@Composable
fun OrderSummaryContent(
state: OrderSummaryUiState,
onPay: () -> Unit,
onEditAddress: () -> Unit,
modifier: Modifier = Modifier,
) {
Column(modifier.fillMaxSize().background(MaterialTheme.colorScheme.surface).padding(16.dp)) {
Text(stringResource(R.string.order_summary_title), style = MaterialTheme.typography.headlineSmall)
LazyColumn(Modifier.weight(1f).padding(vertical = 8.dp)) {
items(state.items, key = { it.id }) { line ->
ListItem(headlineContent = { Text(line.name) }, trailingContent = { Text(line.priceText) })
}
}
Row(verticalAlignment = Alignment.CenterVertically) {
Text(state.address, Modifier.weight(1f), style = MaterialTheme.typography.bodyMedium)
IconButton(onClick = onEditAddress) { // 48dp target by default
Icon(Icons.Default.Edit, contentDescription = stringResource(R.string.edit_address))
}
}
Button(onClick = onPay, modifier = Modifier.fillMaxWidth()) {
Text(stringResource(R.string.pay_amount, state.totalText))
}
}
}Review checklist for generated UI
- โ Stateless: data in, events out; no fake data or local business state
- โ Theme tokens only: no hard-coded colours, sizes or fonts
- โ Strings in resources; formatted amounts from state
- โ Accessibility: content descriptions, 48dp targets, contrast, sensible reading order
- โ Lists are lazy with stable keys
- โ Works at large font scale, dark mode, small and wide screens
- โ Previews and screenshot tests added
Where AI UI generation shines
First drafts from mockups
Saves layout boilerplate, with you refining structure and tokens.
Preview generation
Realistic preview data and multi-config previews for existing composables.
Variants
Empty, loading and error states derived from an existing design.
Frequently asked questions
Can AI match my design system exactly?
Only if it knows it. Provide your theme and components in context, or rules telling it to use AppButton and similar, then review.
Is generated UI accessible?
Often partially. Check with Android Studio's accessibility checks, TalkBack, and screenshot tests at large font scale.
Should I generate whole screens or components?
Components or single screens with clear boundaries. Large generations are harder to review and fix.
Conclusion
Use AI to draft Compose UI quickly, then make it production-ready with state hoisting, theme tokens, string resources, accessibility, lazy lists and tests. Better prompts reduce the clean-up, but review is always required.
Next step: apply the same discipline to logic in Using AI to Write Kotlin Code Responsibly.
Official references
๐ฑ Apps built by Yunok Tech
Real Android apps on Google Play, free to download.
Walzi4K wallpapers for lock and home screenGet it โธ
NotiVaultNotification history: recover dismissed notificationsGet it โธ
Ready to build real Android applications?
AI coding tools multiply what you already know. The stronger your Kotlin, Compose and architecture foundation, the better you can judge, fix and ship what these tools suggest.
Move beyond theory and strengthen your Android development skills with Yunoktech's Android course. Learn core concepts, practical implementation, modern Android development techniques, and the reasoning behind building maintainable applications.
Explore the Android course and take your next step as an Android developer.