Tech Sheets

How to use Scaffold in Jetpack Compose

最終更新日: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()
        }
    }
}

一覧に戻る