[英]Have you recently discouraged using naviation component?
I am using bottom navigation
for single activity
.我正在为
single activity
使用bottom navigation
。
What I'm trying to do is do various screen transitions through the bottom menu
( fragment
).我要做的是通过
bottom menu
( fragment
)进行各种屏幕转换。 And we are implementing a function to switch screens without moving the menu on the switched screen.我们正在实施 function 来切换屏幕,而无需移动切换屏幕上的菜单。
I've considered using the BottomNavigation Activity
provided by Android (probably the JetPack navigation component
).我考虑过使用 Android (可能是
JetPack navigation component
)提供的BottomNavigation Activity
。
However, I saw that there were many problems with this component.但是,我看到这个组件有很多问题。 Especially the
NavController
.特别是
NavController
。
For example, when i switch screens and then come back, i have to manually restore the view state.例如,当我切换屏幕然后返回时,我必须手动恢复视图 state。
Because NavController
uses replace()
instead of show/hide
, so I've been told so因为
NavController
使用replace()
而不是show/hide
,所以有人告诉我
In addition to these problems, using FragmentManager
and show/hide
is more recommended, is it true?除了这些问题,更推荐使用
FragmentManager
和show/hide
,是真的吗?
So I'm currently using setOnNavigationItemSelectedListener
, but it's actually more difficult because I'm implementing the screen transition myself.所以我目前正在使用
setOnNavigationItemSelectedListener
,但实际上更困难,因为我自己实现了屏幕转换。
I would definitely use the provided NavController if I was you.如果我是你,我肯定会使用提供的 NavController。
It has had its issues over the years, some of them which you are describing.多年来,它一直存在问题,您正在描述其中一些问题。 Most of these problems were removed in version 2.4.0-alpha01 .
大多数这些问题已在2.4.0-alpha01 版本中删除。 Version 2.4.0-alpha02 is also out now.
2.4.0-alpha02 版现在也发布了。
Check out this sample to see the BottomNavigationView in action, together with the new NavController.查看此示例以查看运行中的 BottomNavigationView 以及新的 NavController。 It is a great starting point for any app.
对于任何应用程序来说,它都是一个很好的起点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.