android:토스트메시지
토스트메시지
문서의 이전 판입니다!
의의
안드로이드에서 토스트 메시지를 만드는 함수 예제이다.
개발시에 log 대신에 사용해도 괜찮다.
토스트 메시지 만들기
val notification = rememberSaveable { mutableStateOf("") } if (notification.value.isNotEmpty()) { Toast.makeText(LocalContext.current, notification.value, Toast.LENGTH_LONG).show() notification.value = "" }
토스트 메시지 부르기
Text(text = "Cancel", modifier = Modifier.clickable { notification.value = "Cancelled" })
전체 예제
@Composable
fun SettingsPage(modifier : Modifier = Modifier) {
val notification = rememberSaveable { mutableStateOf("") }
if (notification.value.isNotEmpty()) {
Toast.makeText(LocalContext.current, notification.value, Toast.LENGTH_LONG).show()
notification.value = ""
}
Column (modifier = modifier
.background(GreenColorJC)
.padding(8.dp)
.verticalScroll(rememberScrollState())
.safeDrawingPadding(),
) {
Row(modifier = modifier
.fillMaxWidth()
.padding(8.dp)
) {
Text(text = "Cancel", modifier = Modifier.clickable { notification.value = "Cancelled" })
Text(text = "Save", modifier = Modifier.clickable { notification.value = "Saved" })
}
}
}
android/토스트메시지.1722092218.txt.gz · 마지막으로 수정됨: 저자 이거니맨

로그인