Mokera

Tech Sheets

mokelab

How to use Scaffold in Jetpack Compose

Last updated:2024-07-10

Let's use Scaffold in our app,based on the Google sample.

Create MyApp composable

Create a MyApp Composable that will be responsible for the entire app's configuration.

@Composable
fun MyApp() {
    ComposeAppTheme {
        Scaffold {
            MainScreen()
        }
    }
}

Call Scaffold . In the content section, we will display MainScreen , which represents the main screen.

Use MyApp

Call MyApp at setContent in MainActivity .

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyApp()
        }
    }
}

Back