Jetpack Compose is built around composable functions. These functions
let you define your app's UI programmatically by describing how it
should look and providing data dependencies, rather than
focusing on the process of the UI's construction (initializing an
element, attaching it to a parent, etc.).
To create a composable function, just add the @Composable annotation
to the function name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.composesample | |
import android.os.Bundle | |
import androidx.activity.ComponentActivity | |
import androidx.activity.compose.setContent | |
import androidx.compose.material.MaterialTheme | |
import androidx.compose.material.Surface | |
import androidx.compose.material.Text | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.tooling.preview.Preview | |
import com.example.composesample.ui.theme.ComposeSampleTheme | |
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
ComposeSampleTheme { | |
// 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 | |
@Composable | |
fun DefaultPreview() { | |
ComposeSampleTheme { | |
Greeting("Android") | |
} | |
} |
Enjoy Coding.... :)
0 comments:
Post a Comment