[英]Use image as item in menu for Navigation Menu Drawer
I'm creating a project with Navigation Drawer Menu in Android, however, so far the menu only shows an icon and title in the menu. 我正在使用Android中的导航抽屉菜单创建项目,但是,到目前为止,菜单仅在菜单中显示图标和标题。
How do I change the whole menu item to become an image with text inside? 如何更改整个菜单项以成为包含文本的图像?
Currently: the menu is: 目前:菜单是:
However, I would prefer it to be like this: 但是,我希望它是这样的:
You should use listview or recycler view in your NavigationView
like this: 您应该在
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>
After that, set data in Listview
. 之后,在
Listview
设置数据。
You may use NavigationView#addHeaderView(View)
API and provide your custom view as a content of NavigationView
. 您可以使用
NavigationView#addHeaderView(View)
API并将自定义视图作为NavigationView
的内容提供。
The alternative is to use app:headerLayout="@layout/your_layout"
through xml. 另一种方法是使用
app:headerLayout="@layout/your_layout"
到xml。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.