Getting Started with Jetpack Compose
Jetpack Compose is a New UI Toolkit replaces / introp with tradition XML code for android UI Development, it has wide range of support with android architecture component, lifecycle, viewmodel...
Let start with the basic example,
Note: Jetpack compose is not stable yet, it was in beta at the time of writing
I am using Android Studio Artic Fox | 2020.3.1 canary 14
Since Jetpack compose is not stable yet, you won`t get this option in stable version of android studio
Start new jetpack compose project
Name the Project and Package Name
Finally Hit Finish
MainActivity.kt
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
SampleTheme {
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
Greeting("Android")
}
}
}
}
}
@Composable
fun Greeting(name: String) {
Text(text = "Hello $name!")
}
@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
SampleTheme {
Greeting("Android")
}
}
you will get nice preview in android studio
Thats all for now. meet you later with onather jetpack compose example
Thanks. stay safe, Keep Code