사용자 도구

사이트 도구


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" })

전체 예제

settingScreen.kt
@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/토스트메시지.txt · 마지막으로 수정됨: 2024/07/28 01:47 저자 이거니맨