可以通过在BottomNavigationItem中设置icon和label属性来将图标和文字显示出来。示例代码如下:
val items = listOf(
BottomNavigationItem(
icon = {
Icon(Icons.Default.Home, contentDescription = "Home")
},
label = { Text("Home") }
),
BottomNavigationItem(
icon = {
Icon(Icons.Default.Search, contentDescription = "Search")
},
label = { Text("Search") }
),
BottomNavigationItem(
icon = {
Icon(Icons.Default.AccountCircle, contentDescription = "Profile")
},
label = { Text("Profile") }
)
)
BottomNavigation(
items = items,
selectedItemId = selectedItem.value,
onSelected = {
selectedItem.value = it
}
)
其中,BottomNavigationItem的icon和label属性可以分别设置为显示的图标和文字内容。在上例中,我们使用了Compose内置的Icon和Text组件来显示图标和文字。注意确保图标资源已被正确导入并存在。