I have following design in my project - Activity (which have menuitems A, B, C, D) if we click on menuItem A then a FragmentA opens.I'm adding this fragment on top of activity, So toolbar remains same. FragmentA onCreateView is -
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
rootView = inflater.inflate(R.layout.fragment_a, container, false)
Activity.toolbar.setTitle("FragmentA");
Activity.toolbar.setNavigationIcon(R.drawable.back_icon);
Activity.toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Activity.fragmentManager.popBackStack();
Activity.toolbar.setTitle("Activity");
}
});
}
So Basically in FragmentA I inflate Back Navigation Icon on toolbar. but i want to hide this icon when switch back to my Activity. I don't have any navigation icon or logo in Activity.
yourActionBarDrawer. setDrawerIndicatorEnabled(false); This will remove the hamburger icon on toolbar completely.
If you want to change the visibility of your menu items on the go you just need to set a member variable in your activity to remember that you want to hide the menu and call invalidateOptionsMenu() and hide the items in your overridden onCreateOptionsMenu(...) method.
Try setting the NavigationIcon to null while getting back to activity.
Activity.toolbar.setNavigationOnClickListener(new View.OnClickListener( {
@Override
public void onClick(View view) {
Activity.fragmentManager.popBackStack();
Activity.toolbar.setTitle("Activity");
Activity.toolbar.setNavigationIcon(null);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With