简体   繁体   English

如何在 Android 设计库中的 NavigationView 上放置计数器?

[英]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.

相关问题 使用Android设计支持库中的NavigationView - Using NavigationView from Android Design Support Library Android设计库23.1.0 NavigationView - Android Design Library 23.1.0 NavigationView Android - Material Design - NavigationView - 如何放置垂直滚动? - Android - Material Design - NavigationView - How to put vertical scroll? 如何将页脚添加到 NavigationView - Android 支持设计库? - How to add footer to NavigationView - Android support design library? 如何通过支持设计库中的NavigationView使用Framelayout - How to use Framelayout with NavigationView from Support Design Library Android设计支持库:NavigationView源代码 - Android Design Support Library: NavigationView source code 如何设计Design Support库的NavigationView样式? - How to style the Design Support library's NavigationView? 自定义NavigationView-添加动态headerView,Android支持设计库 - Customising NavigationView - Adding dynamic headerView, Android Support Design Library 如何从设计支持库以编程方式访问位于 NavigationView 标头内的微调器? - How do I programatically access a spinner located inside the header of the NavigationView from the design support library? Android:如何在Android Studio 1.5.1中从右将android.support.design.widget.NavigationView设置为打开? - Android: How to set android.support.design.widget.NavigationView open from right in android studio 1.5.1?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM