英文:
Why do I need to add a dependency on material when I use material3 when I want to use e.g. BottomNavigation?
问题
I don't understand the difference between these two dependencies and why I need them to create e.g. a BottomNavigationItem
in M3.
So these are my dependencies:
def composeBom = platform("androidx.compose:compose-bom:2023.05.01")
implementation composeBom
androidTestImplementation composeBom
implementation 'androidx.compose.material3:material3'
implementation 'androidx.compose.material:material'
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.runtime:runtime-livedata'
Now why do I need a dependency on both androidx.compose.material3:material3
and androidx.compose.material:material
to use BottomNavigationItem
and just a regular M3 Text
? Isn't this dependency androidx.compose.material:material
just M1? Why isn't BottomNavigationItem
available in M3?
Because I need to have dependencies on both, I always need to specify which library I want to use when I want to create a UI component, like IconButton
:
I already made many mistakes by importing the UI components from both the M3 library and the other one, causing a strange UI because the components are rendered differently.
Why isn't BottomNavigationItem
in M3, but many components are? Like Scaffold
, Text
, Button
, etc.
英文:
I don't understand the difference between these two dependencies and why I need them to create e.g. a BottomNavigationItem
in M3.
So these are my dependencies:
def composeBom = platform("androidx.compose:compose-bom:2023.05.01")
implementation composeBom
androidTestImplementation composeBom
implementation 'androidx.compose.material3:material3'
implementation 'androidx.compose.material:material'
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.runtime:runtime-livedata'
Now why do I need a dependency on both androidx.compose.material3:material3
and androidx.compose.material:material
to use BottomNavigationItem
and just a regular M3 Text
? Isn't this dependency androidx.compose.material:material
just M1? Why isn't BottomNavigationItem
available in M3?
Because I need to have dependencies on both, I always need to specify which library I want to use when I want to create a UI component, like IconButton
:
I already made many mistakes by importing the UI components from both the M3 library and the other one, causing a strange UI because the components are rendered differently.
Why isn't BottomNavigationItem
in M3, but many components are? Like Scaffold
, Text
, Button
, etc.
答案1
得分: 1
在Material 3中,您使用NavigationBar
和NavigationBarItem
代替BottomNavigationBar
。
要在屏幕底部使用NavigationBar
,您可以使用Scaffold
并将NavigationBar
传递给bottomBar
参数:
Scaffold(
bottomBar = { NavigationBar {
NavigationBarItem(
icon = ...
label = ...
onClick = ...
selected = ...
)
...
},
content = ...
}
英文:
In Material 3 you have a NavigationBar
and a NavigationBarItem
instead of a BottomNavigationBar
.
To use a NavigationBar
at the bottom of the screen you use a Scaffold
and pass the NavigationBar
in the bottomBar
parameter:
Scaffold(
bottomBar = { NavigationBar {
NavigationBarItem(
icon = ...
label = ...
onClick = ...
selected = ...
)
...
},
content = ...
}
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论