简体   繁体   English

关于Android中BottomNavigationView的问题

[英]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 个按钮:

  • Back后退
  • Info信息
  • Stats统计数据
  • My Orders我的订单

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:所以基本上我有两个问题:

  1. Should the Activities 'Info', 'Stats', and 'My Orders' be real Activities or just Fragments?活动“信息”、“统计”和“我的订单”应该是真实的活动还是只是片段? Normally I think that at leat 'Stats', and 'My Orders' should be real Activities as they are persistent.通常我认为至少“统计”和“我的订单”应该是真实的活动,因为它们是持久的。 But in many BottomNavigationView only Fragments are used?但是在许多 BottomNavigationView 中只使用 Fragments 吗?
  2. How can I pass content information to the Activity/Fragment 'Info'.如何将内容信息传递给 Activity/Fragment 'Info'。 This Activity/Fragment should display information based on the Activity is was called from.这个 Activity/Fragment 应该显示基于 Activity 被调用的信息。 Let's say the Activities are different dishes.假设活动是不同的菜肴。 Do I have to create a separate Info-Activity/Fragment for each dish?我必须为每道菜创建一个单独的信息活动/片段吗? Or can I somehow define a dynamic Activity/Fragment that displayes information based on the current Activity?或者我可以以某种方式定义一个基于当前活动显示信息的动态活动/片段?

I'd appreciate every comment and I'd really appreciate your help.我会很感激每一条评论,我真的很感激你的帮助。

  1. The recommended approach is Single Activity and Multiple fragments .推荐的方法是Single ActivityMultiple fragments You can do this using Jetpack's Navigation Component您可以使用Jetpack's Navigation Component来执行此操作
  2. In case you need to pass 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 fragmentmake 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM