我有一个问题。我试图更改默认的选项菜单中,对于每一个片段不同。我创建了每一个片段的XML文件,我的推杆他们里面RES /菜单文件夹。现在我不知道如何告诉机器人来更改默认选项菜单每一个片段。我的推杆寻呼机视图中的片段。我说的菜单是在靠近家和后退按钮底部的之一。
这是自定义菜单之一
<菜单的xmlns:机器人=http://schemas.android.com/apk/res/android 的xmlns:工具=http://schemas.android.com/tools 工具:上下文=com.example.prova.Frase> <项目 机器人:ID =@ + ID /一 机器人:标题=Scatta图片/> <项目 机器人:ID =@ + ID /两个 机器人:标题=Scegli DAL Rullino/> <项目 机器人:ID =@ + ID /三 机器人:标题=Prossimo sfondo predefinito/>&所述; /菜单>
你必须重写每一个片段解决方案
onCreateOptionsMenu
。不要忘了叫 setHasOptionsMenu(真);
(在的onCreate
例如)。 在这里你可以找到 onCreateOptionsMenu
的文档
i have a problem. I am trying to change the default option menu, different for every fragment. I created an xml file for every fragment and i putted them inside res/menu folder. Now i don't know how to tell android to change the default options menu in every fragment. I putted the fragment inside a pager view. The menu i am talking about is the one on the bottom near the home and back buttons.
this is one of the custom menu
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.prova.Frase" >
<item
android:id="@+id/one"
android:title="Scatta Foto"/>
<item
android:id="@+id/two"
android:title="Scegli dal Rullino"/>
<item
android:id="@+id/three"
android:title="Prossimo sfondo predefinito"/>
</menu>
解决方案
on every fragment you have to override onCreateOptionsMenu
. Don't forget to call setHasOptionsMenu(true);
(in onCreate
e.g.). Here you can find onCreateOptionsMenu
's documentation