[英]How to put counter on NavigationView from Android Design Library?
I see tutorial about making navigation drawer using design library here .我在这里看到关于使用设计库制作导航抽屉的教程。 It really does help creating navigation drawer a lot easier.它确实有助于更轻松地创建导航抽屉。 But, many tutorial on internet just show a list of item with image on the left.但是,互联网上的许多教程只显示左侧带有图像的项目列表。 What if I want to put a counter next to the item title?如果我想在商品标题旁边放置一个计数器怎么办? Just like next to followers and badges in the following image.就像在下图中的关注者和徽章旁边一样。 Could I do that or I need to use the old way to make navigation drawer (using layout insteand of xml menu)?我可以这样做还是我需要使用旧方法来制作导航抽屉(使用布局代替 xml 菜单)?
In new NavigationDrawer they have not mention an about the counter you are lookig for.在新的 NavigationDrawer 中,他们没有提到您正在寻找的计数器。 But you can avoid the older way to put counter.但是您可以避免使用较旧的放置计数器的方法。
Because Navigation can contain any child view so you can use it like this.因为 Navigation 可以包含任何子视图,所以您可以像这样使用它。
<android.support.design.widget.NavigationView
android:id="@+id/navView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start">
<ListView
android:entries="@array/test"
android:id="@+id/lvData"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.design.widget.NavigationView>
So just reference your listview and give the customize layout as you want.因此,只需引用您的列表视图并根据需要提供自定义布局。
I know it is Older way of listview.我知道这是列表视图的旧方式。 But it will reduce the code of NavigationDrawer.但是会减少NavigationDrawer的代码。 I hope it helps you.我希望它能帮助你。
Note : Never use app:menu and child view in NavigationView at the same time.注意:切勿同时在 NavigationView 中使用 app:menu 和子视图。 Otherwise it will overlap each other.否则会相互重叠。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.