DailyDeskTools home

XML to Jetpack Compose Converter

Turn Android XML layouts into Jetpack Compose (Material 3) Kotlin code, with imports and a preview.

  • Free forever
  • No signup
  • Runs on your device
XML to Compose ConverterRuns locally · nothing uploaded
Loading tool…

Watch the XML to Compose Converter in action

Android is now Compose First and Views are in maintenance mode. See how to convert an Android XML layout to Jetpack Compose code in your browser: paste the layout, name the composable and copy the Kotlin.

Watch on its own page

How to use the XML to Compose Converter

  1. 1Paste an Android XML layout file, or start from the sample.
  2. 2Read the Compose code on the right. It updates as you type.
  3. 3Name the composable, and choose imports, a @Preview and ID comments.
  4. 4Check the TODO comments for anything that needs finishing by hand.
  5. 5Copy the code or download it as a .kt file.

How the conversion works

The converter reads your layout in your browser and writes the matching Jetpack Compose code with Material 3 components. Each view becomes a composable, and its layout attributes become a Modifier chain in the order Compose expects: size, weight and alignment, then margins, background and padding.

Text fields, checkboxes, switches and sliders get their own remember { mutableStateOf(...) } state, named after the view's ID, so the code compiles and works straight away.

XML views and their Compose equivalents

Android XML Jetpack Compose
LinearLayout (vertical) Column
LinearLayout (horizontal) Row
FrameLayout Box
ScrollView Column + verticalScroll
TextView Text
Button / MaterialButton Button, OutlinedButton or TextButton
EditText / TextInputLayout TextField / OutlinedTextField
ImageView Image + painterResource
CheckBox / Switch Checkbox / Switch in a Row
ProgressBar CircularProgressIndicator / LinearProgressIndicator
SeekBar Slider
CardView Card
RecyclerView LazyColumn / LazyRow
View (1dp line) HorizontalDivider

Attributes

  • Sizes: match_parent becomes fillMaxWidth() or fillMaxHeight(), fixed sizes become width(), height() or size(), and layout_weight becomes weight().
  • Spacing: margins become padding before the background, and padding comes after it, which is how Compose separates the two.
  • Text: textSize, textColor, textStyle, maxLines, ellipsize and textAllCaps are converted. @string, @color, @dimen and @drawable references become stringResource, colorResource, dimensionResource and painterResource.
  • Alignment: gravity becomes the Column or Row arrangement and alignment, and layout_gravity becomes Modifier.align().
  • Inputs: inputType sets the keyboard type, and password fields get PasswordVisualTransformation().

What needs a human

Some XML has no one-to-one Compose version. ConstraintLayout and RelativeLayout positions, custom views, fragments, <include> layouts and drawable backgrounds are kept as // TODO comments rather than guessed, and any attribute that was not converted is listed above its view. RecyclerView becomes a LazyColumn with a placeholder row for you to replace with your item layout.

Privacy

Your layout is converted only in your browser. Nothing is uploaded, so it is safe to paste code from private projects.

Frequently asked questions

Doesn't Android Studio convert XML to Compose now?

Android Studio Canary has an AI Migration Assistant (right-click a layout, then AI > Migrate to Compose) that uses an AI coding agent. This converter is different: it works instantly in any browser with fixed rules, needs no AI agent, account or Canary build, and the same layout always gives the same code.

Does the converter support ConstraintLayout?

Its views are converted, but constraints are not. They are placed in a Box with a TODO comment, so you can rebuild the layout with Column and Row or with ConstraintLayout for Compose.

Which Compose version does it target?

Material 3 (androidx.compose.material3), with current APIs such as HorizontalDivider and the lambda form of LinearProgressIndicator progress.

How are margins converted?

Compose has no margins. A margin becomes Modifier.padding placed before the background, and XML padding becomes Modifier.padding placed after it.

Is my code uploaded anywhere?

No. The conversion runs entirely in your browser, so your layouts never leave your device.

Last updated