On this page
A typical XML screen involves a layout file, a Fragment with View Binding, a RecyclerView adapter, some custom styles and a few click listeners. Converting it to Compose is mostly mechanical, which suits AI, but behaviour hides in the details: focus handling, IME actions, accessibility, saved state.
A safe, repeatable process
Conversion prompt
Convert this screen to Jetpack Compose.
Inputs: fragment_orders.xml, item_order.xml, OrdersAdapter.kt, OrdersFragment.kt, OrdersUiState.kt.
Requirements:
- Stateless `OrdersContent(state: OrdersUiState, onOrderClick: (String) -> Unit, onRetry: () -> Unit)`.
- RecyclerView โ LazyColumn with key = order.id; preserve item layout, spacing and text styles
using our AppTheme (Material 3) tokens, not raw colors.
- Preserve behaviour: empty state, error + retry, swipe-to-refresh, content descriptions.
- List anything in the XML you could not map exactly (custom attrs, styles, animations).
- Add previews for loading, empty, error and 3 items.
Do not change OrdersViewModel.View โ Compose mapping reference
| XML / View | Compose | Watch out for |
|---|---|---|
| LinearLayout (vertical/horizontal) | Column / Row | Weights โ Modifier.weight |
| ConstraintLayout | Row/Column/Box, or ConstraintLayout for Compose | Prefer simple layouts where possible |
| RecyclerView + Adapter | LazyColumn / LazyVerticalGrid | Stable keys; item decorations |
| EditText | TextField / OutlinedTextField | IME actions, input types, state hoisting |
| SwipeRefreshLayout | PullToRefreshBox (Material 3) | Refresh state from ViewModel |
| visibility="gone" | Conditional composition (if) | Animations (AnimatedVisibility) |
| Custom View | Rewrite, or wrap with AndroidView | Keep complex working Views wrapped at first |
| Styles/themes | MaterialTheme tokens | Bridge the XML theme and Compose theme during migration |
Hosting during migration
class OrdersFragment : Fragment() {
private val viewModel: OrdersViewModel by viewModels()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) =
ComposeView(requireContext()).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
AppTheme {
val state by viewModel.uiState.collectAsStateWithLifecycle()
OrdersContent(state, onOrderClick = ::openOrder, onRetry = viewModel::retry)
}
}
}
private fun openOrder(id: String) { /* existing navigation */ }
}Verifying equivalence
- Screenshot tests of the old and new screens across states, dark mode and large fonts. See Screenshot Testing.
- UI tests for interactions: clicks, retry, refresh, text input.
- Accessibility checks with TalkBack: reading order and descriptions often change silently.
- Performance on a release build: lazy lists with keys, no heavy work in item composables.
Prioritising screens
Start with
Leaf screens with simple state, such as settings and detail pages, to build team patterns.
Then
List screens with adapters, where Compose removes the most code.
Later
Complex custom Views and heavy animations. Wrap first, rewrite when valuable.
Frequently asked questions
Can AI convert a whole app at once?
It can generate a lot of code, but reviewing and verifying it all at once is impractical. Screen-by-screen migration with tests is far safer.
Should navigation move to Compose first?
Usually last. Migrate screens inside existing Fragments, then move navigation once most screens are composables.
Will the app size grow during migration?
Temporarily, since both UI systems ship. It typically improves once View-based dependencies are removed.
Conclusion
Let AI do the mechanical conversion of layouts and adapters into stateless composables, while you keep the ViewModel unchanged, host with ComposeView, and prove equivalence with screenshots, UI tests and accessibility checks, one screen at a time.
Next step: understand the more autonomous tools in AI Agents in Android Development.
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?
Jetpack Compose clicks once you build real screens with real state. Practise modern Android UI development on projects that go beyond toy examples.
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.