Replacing XML layouts with JetPack Compose in android

Abdul Qadir
5 min readJul 25, 2024

Jetpack Compose is a modern tool for building Android UIs, simplifying and accelerating development with less code.

Some of Key features of Compose:

  1. Declarative UI: Define UI components in code rather than XML.
  2. Kotlin Integration: Write UI code in Kotlin, the same language used for app logic.
  3. Composable: Functions that define UI elements and update automatically with state changes.
  4. Theming: Simplified customization using Material Design components.

Basic Structure of Compose

An explanation of Composable functions

Composable functions are the basic building block of a UI.

Compose Annotations

Annotations are to attach extra information to code.

The following diagram is an example of annotated function:

In compose Annotations can take parameters. Parameters provide extra information to the tools processing them.

Below is the example of @Preview annotation for Compose with and without Arguments.

  1. @Preview()
  2. @Preview(showBackground…

--

--

Abdul Qadir

Android developer, my strengths include but not limited to Java, Android Mobile Application Development, Kotlin, Unity3D