![](/img/trans.png)
[英]How to use setOnLongClickListener on menu item in navigation drawer in Android?
[英]Use image as item in menu for Navigation Menu Drawer
我正在使用Android中的导航抽屉菜单创建项目,但是,到目前为止,菜单仅在菜单中显示图标和标题。
如何更改整个菜单项以成为包含文本的图像?
目前:菜单是:
但是,我希望它是这样的:
您应该在NavigationView
使用listview或recycler视图,如下所示:
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/Mainheader"
layout="@layout/nav_header" />
<ListView
android:id="@+id/exp_navigationmenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary" />
</LinearLayout>
</android.support.design.widget.NavigationView>
之后,在Listview
设置数据。
您可以使用NavigationView#addHeaderView(View)
API并将自定义视图作为NavigationView
的内容提供。
另一种方法是使用app:headerLayout="@layout/your_layout"
到xml。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.