我有一个活动包含使用片段的3个标签。我想在标签移动时加载/更改工具栏菜单。
public class SpendsFragment extends Fragment {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
MenuItem menuInicio = menu.add(0, 0, 0, "Início");
menuInicio.setIcon(android.R.drawable.ic_menu_edit);
MenuItem menuBusca = menu.add(1, 1, 0, "Buscar");
menuBusca.setIcon(android.R.drawable.ic_menu_search);
setHasOptionsMenu(true);
super.onCreateOptionsMenu(menu, inflater);
}
}
public class MoneyFragment extends Fragment {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
MenuItem menuInicio = menu.add(0, 0, 0, "Edit");
menuInicio.setIcon(R.drawable.xyz);
MenuItem menuBusca = menu.add(1, 1, 0, "Delete");
menuBusca.setIcon(R.drawable.abc);
setHasOptionsMenu(true);
super.onCreateOptionsMenu(menu, inflater);
}
}