У меня есть рамка, в которую я помещаю различные фрагменты. У некоторых отображается панель действий, у некоторых - нет. Но тот, что приведен ниже, не отображает панель действий, как другие.
public class AFragment extends Fragment {
View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_a, container, false);
ButterKnife.bind(this, view);
setHasOptionsMenu(true);
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_a, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_a) {
//getFragmentManager().popBackStackImmediate();
}
return super.onOptionsItemSelected(item);
}
}
Этот фрагмент вызывается из предыдущего фрагмента, как
AFragment aFragment = new AFragment ();
getFragmentManager().beginTransaction()
.replace(R.id.fragment, aFragment , "fragment_a")
.setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.addToBackStack(null)
.commit();
Кстати, я не показываю панель действий в предыдущем фрагменте.
В случае необходимости, styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppActionBar" parent="AppTheme">
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
</style>