I would like to show custom toast. How to achieve this?
This is my code, but this is deprecated and it crashes with logs:
java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from androidx.compose.ui.platform.ComposeView{3ed3fe7 V.E...... ......I. 0,0-0,0}
Toast
.makeText(context, "TESTTESTTEST", Toast.LENGTH_SHORT)
.apply {
view = ComposeView(context).apply {
setContent {
CustomToastWithIcon(
message = stringResource(id = R.string.cart),
ImageVector.vectorResource(id = R.drawable.ic_info)
)
}
}
}
.show()
I tried defining it like this, but still crash.
val composeView = ComposeView(context).apply {
setViewTreeLifecycleOwner(this.findViewTreeLifecycleOwner())
setContent {
CustomToastWithIcon(
message = stringResource(id = R.string.cart),
ImageVector.vectorResource(id = R.drawable.ic_info)
)
}
Also read: Custom Toast in Jetpack Compose
Or is it possible to change background and icon from function
Toast
.makeText(context, message, Toast.LENGTH_SHORT)
Edit: Snackbar with scaffold was a solution