如何包括在Android的菜单XML多个菜单共同的菜单项? [英] How to include a common menu item in multiple menus in Android menu xml?

查看:145
本文介绍了如何包括在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>

菜单/ other.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>

我知道,这是可能的programmaticaly做到这一点,但我认为XML的方式是更好的。

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

感谢您,

穆尔

推荐答案

AFAIK,&LT;包括&GT; 仅适用于布局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天全站免登陆