[英]Question about BottomNavigationView in Android
I have general questions about BottomNavigationView.我有关于 BottomNavigationView 的一般性问题。 I would like to have a BottomNavigationView in each of my Activities in an App for ordering something (eg food).我想在应用程序中的每个活动中都有一个底部导航视图,用于订购某些东西(例如食物)。 It should have 4 buttoms:它应该有 4 个按钮:
With 'Back' the app should just go back to the previous activity.使用“返回”,应用程序应该只是 go 回到上一个活动。 The buttoms 'Stats' and 'My Orders' should switch to a persistent activity that should not be destroyed when not being displayed.按钮“统计”和“我的订单”应切换到不显示时不应被破坏的持久活动。 'My Orders' should display the last orders. “我的订单”应显示最后的订单。 The buttom 'Info' should only display some information about the current item or current menu (depending from which activity it is called).按钮“信息”应该只显示有关当前项目或当前菜单的一些信息(取决于调用它的活动)。 So basically I have 2 questions:所以基本上我有两个问题:
I'd appreciate every comment and I'd really appreciate your help.我会很感激每一条评论,我真的很感激你的帮助。
Single Activity
and Multiple fragments
.推荐的方法是Single Activity
和Multiple fragments
。 You can do this using Jetpack's Navigation Component
您可以使用Jetpack's Navigation Component
来执行此操作data from an Activity/Fragment to the new calling Fragment
, it can be done by setting arguments on the calling fragment
and then getting it on the called fragment
.如果您需要将data from an Activity/Fragment to the new calling Fragment
,可以通过在调用 Fragment setting arguments on the calling fragment
被调用 Fragment 上getting it on the called fragment
完成。 If there is something which requires to be dynamic, for example- dishes fragment
, make a single fragment and common layout and load the data dynamically from the backend
.如果有something which requires to be dynamic, for example- dishes fragment
, make a single fragment and common layout and load the data dynamically from the backend
。For Setting Arguments , this should help对于设置 Arguments ,这应该会有所帮助
How to pass a variable from Activity to Fragment, and pass it back? 如何将变量从 Activity 传递到 Fragment,并将其传回?
Note: You can use fragment without using Navigation Components
but you have to use FragmentManager and FragmentTransaction and also have to maintain the Backstack by yourself which could be quite complicated
注意:您可以在不使用Navigation Components
的情况下使用片段,但您必须使用FragmentManager and FragmentTransaction and also have to maintain the Backstack by yourself which could be quite complicated
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.