Compose

Intent

----___<<<<< 2023. 5. 4. 09:01

 

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
) {
MyBtn()
}
}
}
}
}
@Composable
fun MyBtn(){
val context = LocalContext.current
Button(onClick = {
val intent = Intent(context, MySecondActivity::class.java)
context.startActivity(intent)
}) {
Text(text = "goToSecond")
}
}
@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
MyBtn()
}
}
view raw MainActivity.kt hosted with ❤ by GitHub

'Compose' 카테고리의 다른 글

column  (0) 2023.05.06
xml to compose  (0) 2023.05.05
Image  (0) 2023.04.30
remember  (0) 2023.04.30
TextField  (0) 2023.04.29