答案 0 :(得分:1)
在观看两个图像后,您不需要两个不同的操作栏而是有一个操作栏和两个不同的menu.xml文件,当单击片段1时,请转到firstFragment类的代码:
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_one, menu);//here menu_one.xml is called
return true;
}
和第二个片段在你的secondFragmentclass中调用它
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_two, menu);//here menu_two.xml is called
return true;
}
menu_one.xml和menu_two.xml将根据您的意愿包含不同的项目 menu_one.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/someButton"
android:icon="@drawable/some_button"
android:title="@string/some_button"
android:showAsAction="always"/>
</menu>
menu_two.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/someButton2"
android:icon="@drawable/some_button2"
android:title="@string/some_button2"
android:showAsAction="always"/>
</menu>