如何在Android菜单xml中的多个菜单中包含一个公共菜单项? [英] How to include a common menu item in multiple menus in Android menu xml?

查看:19
本文介绍了如何在Android菜单xml中的多个菜单中包含一个公共菜单项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多菜单总是有一个与所有菜单相同的项目.

Many of menus have always one item same to all.

有没有办法将该项目定义为额外菜单并将其包含在所有其他菜单中?

Is there the way to define that item as extra menu and include it to all other?

像这样:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_main"
          android:title="@string/text_mainmenu" />
</menu>

菜单/其他.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      parent="@menu/main">
    <item android:id="@+id/menu_other"
          android:title="@string/text_othermenu" />
</menu>

我知道,可以通过编程来实现,但我认为 xml-way 更好.

I know, that it's possible to do it programmaticaly, but I thought xml-way is nicer.

推荐答案

AFAIK, <include> 仅适用于布局 XML,不适用于菜单 XML,不过您当然可以尝试一下.缺少这一点,编程选项(扩展两个菜单 XML 文件)是我所知道的唯一选项.

AFAIK, <include> only works for layout XML, not menu XML, though you can certainly give it a try. Lacking that, the programmatic option (inflating both menu XML files) is the only option I am aware of.

这篇关于如何在Android菜单xml中的多个菜单中包含一个公共菜单项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆