首页 > 解决方案 > Android 以编程方式从 Res/menu 获取菜单

问题描述

我正在使用 LinearLayout 创建自定义底部导航。我想Menu用作物品。

<com.sam.grocerystore.views.XBottomNavigation
    android:id="@+id/customBottomNav"
    android:layout_width="match_parent"
    android:layout_height="55dp"/>

在 Java 中

XBottomNavigation xNav = new XBottomNavigation(this);

xNav.inflateMenu(R.menu.bottom_nav_menu);

在 XBottomNavigation 中

public void inflateMenu(@MenuRes int menuRes){
    Menu menu = getMenuFromResID(menuRes);
}

有人可以帮我创造getMenuFromResID功能吗?

标签: javaandroidxml

解决方案


推荐阅读