关于导航抽屉:如何在 Android 设计库中的 NavigationView 上放置计数器? | 珊瑚贝

How to put counter on NavigationView from Android Design Library?


我在这里看到了关于使用设计库制作导航抽屉的教程。它确实有助于更轻松地创建导航抽屉。但是,互联网上的许多教程只是在左侧显示带有图像的项目列表。如果我想在项目标题旁边放一个计数器怎么办?就像下图中的关注者和徽章旁边一样。我可以这样做还是我需要使用旧方法来制作导航抽屉(使用布局而不是 xml 菜单)?

enter

  • 请查看类似问题的答案:stackoverflow.com/questions/30560663/…


在新的 NavigationDrawer 中,他们没有提及您正在寻找的计数器。但是你可以避免使用旧的方式来放置计数器。

因为导航可以包含任何子视图,所以你可以像这样使用它。

1
2
3
4
5
6
7
8
9
10
11
12
13
<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>

所以只需参考您的列表视图并根据需要提供自定义布局。

我知道这是旧的列表视图方式。但是会减少NavigationDrawer的代码。希望对你有帮助。

注意:切勿在 NavigationView 中同时使用 app:menu 和子视图。否则会互相重叠。


来源:https://www.codenong.com/30836986/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8742.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?