我是 Kotlin 新手,正在学习 Room 教程,但是(大约 32 分钟时)我收到一个无法修复的错误:
这是我的代码:
@Composable
fun ContactScreen(
state: ContactState,
onEvent: (ContactEvent) -> Unit
){
Scaffold(
floatingActionButton = {
FloatingActionButton(onClick ={
onEvent(ContactEvent.ShowDialog)
}){
Icon(imageVector = Icons.Default.Add, contentDescription = "Add contact")
}
}
){padding ->
LazyColumn (
contentPadding = padding,
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(16.dp)
){
}
}
}
这些是我的进口:
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.google.android.material.floatingactionbutton.FloatingActionButton
解决方案在评论里:
您导入了错误的
FloatingActionButton
。应该是androidx.compose.material3.FloatingActionButton
。 –
迈克·M.
感谢迈克