#1 ๊ฐ์
Jetpack Compose | Android Developers
์ด ํ์ด์ง๋ Cloud Translation API๋ฅผ ํตํด ๋ฒ์ญ๋์์ต๋๋ค. ์ปฌ๋ ์ ์ ์ฌ์ฉํด ์ ๋ฆฌํ๊ธฐ ๋ด ํ๊ฒฝ์ค์ ์ ๊ธฐ์ค์ผ๋ก ์ฝํ ์ธ ๋ฅผ ์ ์ฅํ๊ณ ๋ถ๋ฅํ์ธ์. Button ๋ฒํผ์ ์ฌ์ฉ์๊ฐ ์ ์๋ ๋ฒํผ์ ํธ๋ฆฌ๊ฑฐํ๋๋ก ํ
developer.android.com
Jetpack Compose์์ ๊ธฐ๋ณธ์ผ๋ก ์ ๊ณต๋๋ Composable ์ค ํ๋์ธ Button์ ๋ํด ์ดํด๋ณธ๋ค.
#2 ์ฝ๋
#2-1 Filled Button
@Composable
fun FilledButtonExample(textParam: String, modifierParam: Modifier = Modifier) {
val context = LocalContext.current
Button(
onClick = { Toast.makeText(context, "Clicked on $textParam", Toast.LENGTH_SHORT).show() },
modifier = modifierParam
) {
Text(text = textParam)
}
}
๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ๋ฒํผ์ด๋ค.
#2-2 Disabled Button
@Composable
fun DisabledButtonExample(textParam: String, modifierParam: Modifier = Modifier) {
val context = LocalContext.current
Button(
onClick = { Toast.makeText(context, "Clicked on $textParam", Toast.LENGTH_SHORT).show() },
modifier = modifierParam,
enabled = false
) {
Text(text = textParam)
}
}
Button์ enabled ์์ฑ์ false๋ก ๋๋ฉด ๋ฒํผ์ด Disabled๋๋ค.
#2-3 Filled Tonal Button
@Composable
fun FilledTonalButtonExample(textParam: String, modifierParam: Modifier = Modifier) {
val context = LocalContext.current
FilledTonalButton(
onClick = { Toast.makeText(context, "Clicked on $textParam", Toast.LENGTH_SHORT).show() },
modifier = modifierParam
) {
Text(text = textParam)
}
}
๋ฒํผ์ ์ฑ์ฐ๋ ๋ฐฐ๊ฒฝ์(Tone)์, ํด๋น ๋ฒํผ์ด ๋ค์ด์๋ Surface์ ์ด์ธ๋ฆฌ๋ ์์ผ๋ก ์์์ ์ผ๋ก ๊ฒฐ์ ํด ๋ง๋ค์ด์ง๋ ๋ฒํผ์ด๋ค.
#2-4 Outlined Button
@Composable
fun OutlinedButtonExample(textParam: String, modifierParam: Modifier = Modifier) {
val context = LocalContext.current
OutlinedButton(
onClick = { Toast.makeText(context, "Clicked on $textParam", Toast.LENGTH_SHORT).show() },
modifier = modifierParam
) {
Text(text = textParam)
}
}
๋ฒํผ์ ๋ฐฐ๊ฒฝ์์ด ์ฑ์์ง์ง ์๊ณ ํ ๋๋ฆฌ๋ง์ผ๋ก ๊ทธ ์์ญ์ ๋๋ฌ๋ด๋ ๋ฒํผ์ด๋ค.
#2-5 Elevated Button
@Composable
fun ElevatedButtonExample(textParam: String, modifierParam: Modifier = Modifier) {
val context = LocalContext.current
ElevatedButton(
onClick = { Toast.makeText(context, "Clicked on $textParam", Toast.LENGTH_SHORT).show() },
modifier = modifierParam
) {
Text(text = textParam)
}
}
๋ฒํผ์ ๋์ด๊ฐ ์๋ ๊ฒ๊ฐ์ ํจ๊ณผ๊ฐ ์ถ๊ฐ๋๋ค.
#2-6 Text Button
@Composable
fun TextButtonExample1(textParam: String, modifierParam: Modifier = Modifier) {
val context = LocalContext.current
TextButton(
onClick = { Toast.makeText(context, "Clicked on $textParam", Toast.LENGTH_SHORT).show() },
modifier = modifierParam
) {
Text(text = textParam)
}
}
@Composable
fun TextButtonExample2(textParam: String, modifierParam: Modifier = Modifier) {
val context = LocalContext.current
Text(
modifier = modifierParam.clickable { Toast.makeText(context, "Clicked on $textParam", Toast.LENGTH_SHORT).show() },
text = textParam
)
}
Text์ฒ๋ผ ๋ณด์ด์ง๋ง Button์ธ ๊ฒฝ์ฐ๋ค. ๊ทธ๋ฅ Text์๋ Modifier์ clickable() ๋ฉ์๋๋ฅผ ์ ์ฉํด ๋ฒํผ์ฒ๋ผ ๋ง๋ค ์๋ ์๋ค. ๋ฌผ๋ก ํ๋ก๊ทธ๋๋จธ๊ฐ ์์๊ฒ ๋ค๋ฌ์ง ์์, ๊ธฐ๋ณธ์ ์ผ๋ก ์ ๊ณต๋๋ ๋ชจ์์๋ง ๋ดค์ ๋๋ TextButton์ ์ฌ์ฉํ๋ ๊ฒ์ด ๋ฏธ๊ด ์ ๋ ์ข๋ค.
#2-7 Icon Button
@Composable
fun IconButtonExample(imageVectorParam: ImageVector, modifierParam: Modifier = Modifier) {
val context = LocalContext.current
IconButton(
onClick = { Toast.makeText(context, "Clicked on ${imageVectorParam.name}", Toast.LENGTH_SHORT).show() },
modifier = modifierParam
) {
Icon(
imageVectorParam,
contentDescription = imageVectorParam.name,
tint = Color.DarkGray,
modifier = Modifier.size(40.dp)
)
}
}
๋ง ๊ทธ๋๋ก ํด๋ฆญ ๊ฐ๋ฅํ ์์ด์ฝ์ด๋ผ๊ณ ๋ณด๋ฉด ๋๋ค. ์ด ๋ฒํผ Composable์ Icon์ ์์ ์์ดํ ์ผ๋ก ๊ฐ๋๋ค. imageVectorParam์ผ๋ก๋ Icons.Filled.Refresh์ ๊ฐ์ด ๊ธฐ๋ณธ์ผ๋ก ์ ๊ณต๋๋ ์์ด์ฝ์ ์ฌ์ฉํ ์ ์๋ค.
#3 ์๋ ํ์ธ

#2์ ๋ชจ๋ ๋ฒํผ์ Column์ ๋ฃ๊ณ ์๋๋ก์ด๋ ํ๋ก์ ํธ๋ฅผ ์คํ์ํจ ๋ชจ์ต์ด๋ค.
#4 ์์ฑ๋ ์ฑ
android-practice/jetpack-compose/Button at master ยท Kanmanemone/android-practice
Contribute to Kanmanemone/android-practice development by creating an account on GitHub.
github.com
'๊นจ์ ๊ฐ๋ ๐ > Android' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Android] Jetpack Compose - State ๊ธฐ์ด (0) | 2024.07.22 |
---|---|
[Android] Jetpack Compose - Lazy Column (0) | 2024.07.22 |
[Android] Jetpack Compose - Layout, Arrangement, Alignment (0) | 2024.07.22 |
[Android] Jetpack Compose - Modifier (0) | 2024.07.22 |
[Android] Jetpack Compose - Surface (0) | 2024.07.22 |