Jetpack Compose 1.6 Essentials was published on April 5, 2024.
The current revision is 1.0. The revision of your book can be found on the copyright page at the start of the book.
A recent update to Android Studio has changed the template code found in the onCreate() function of the MainActivity.kt file. This change replaced the original call to the Surface composable with the Scaffold composable.
The code generated by Android Studio now reads as follows:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
AndroidSampleTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
Greeting(
name = "Android",
modifier = Modifier.padding(innerPadding)
)
}
}
}
}
When the book tells you to modify the onCreate() method to replace the call to Greeting() with a call to MainScreen() or DemoScreen(), you will now need to replace the Scaffolding component with a Surface component. For example:
.
.
import androidx.compose.material3.Surface
.
.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
AndroidSampleTheme {
Surface(
modifier = Modifier.fillMaxSize()
) {
MainScreen()
}
}
}
}
If you have encountered an issue with the book not listed above, please contact us, and we will work to resolve the issue for you as quickly as possible.