Android NavigationView 以编程方式从 XML 设置菜单

标签 android menu

如何以编程方式从 XML 创建 Android 导航 View 菜单?​​

最佳答案

使用设计支持库,您可以轻松添加导航 View 。 在xml中添加以下代码:

    <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:background="@android:color/white"
    app:headerLayout="@layout/layout_drawer_header"
    app:itemTextColor="#000000"
    app:menu="@menu/global"></android.support.design.widget.NavigationView>

然后创建一个用于导航的菜单文件

关于Android NavigationView 以编程方式从 XML 设置菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38794236/

相关文章:

Android Gmail 应用程序 : Horizontal 1px gaps between inline images (images in <td>)

android - 在 Activity 之间切换后未调用 onDestroy

android - 如何更改 Android 的选项菜单位置

wordpress - 在主题激活时自动在位置 'primary menu' 设置菜单

android - 更新多个 Firebase 节点

android - 如何修复 'Process unexpectedly exit'

android - registerForContextMenu 和 setOnCreateContextMenuListener 的区别?

javascript - 如何设置事件的 css 选项卡菜单?

c++ - "A case label may only be used within a switch"

android - Android 上的 VideoVIew 问题