MainActivity.kt
// Compose -> XML
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
DefaultTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Greeting("Android")
}
}
}
}
}
@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
val context = LocalContext.current
Text(
text = "Hello $name!",
modifier = modifier.clickable {
val intent = Intent(context, HappyActivity::class.java)
context.startActivity(intent)
}
)
}
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
DefaultTheme {
Greeting("Android")
}
}
activity_happy.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="<http://schemas.android.com/apk/res/android>"
xmlns:app="<http://schemas.android.com/apk/res-auto>"
xmlns:tools="<http://schemas.android.com/tools>"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HappyActivity">
<TextView
android:text="강의를 들으시는\\n여러분이 챔피언"
android:textSize="50sp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
AndroidManifest.xml
<activity
android:name=".HappyActivity"
android:exported="false"
android:theme="@style/Theme.AppCompat.Light"/>