
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
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
DefaultTheme { | |
MyProgressIndicator() | |
} | |
} | |
} | |
} | |
@Composable | |
fun Greeting(name: String, modifier: Modifier = Modifier) { | |
Text( | |
text = "Hello $name!", | |
modifier = modifier | |
) | |
} | |
@Composable | |
fun MyProgressIndicator(){ | |
// State로 현재 진행률을 관리합니다. | |
var progress by remember { mutableStateOf(0.0f) } | |
Column( | |
modifier = Modifier.fillMaxSize(), | |
verticalArrangement = Arrangement.Center, | |
horizontalAlignment = Alignment.CenterHorizontally | |
) { | |
// 버튼을 클릭할 때마다 progress 값을 변경합니다. | |
Button(onClick = { | |
if (progress < 1.0f) { | |
progress += 0.1f | |
} | |
}) { | |
// 버튼 텍스트 | |
Text( | |
"분노게이지", | |
fontSize = 30.sp | |
) | |
} | |
Spacer(modifier = Modifier.size(30.dp)) | |
// 현재 진행률에 따라 ProgressBar를 표시합니다. | |
LinearProgressIndicator( | |
progress = progress, | |
modifier = Modifier.height(10.dp), | |
color = Color.Red, | |
trackColor = Color.Cyan | |
) | |
} | |
} | |
@Preview(showBackground = true) | |
@Composable | |
fun GreetingPreview() { | |
DefaultTheme { | |
MyProgressIndicator() | |
} | |
} |