Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide NavigationIcon on toolbar

Tags:

android

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.

like image 459
Vikram Avatar asked Oct 29 '15 05:10

Vikram


People also ask

How do I remove navigation drawer?

yourActionBarDrawer. setDrawerIndicatorEnabled(false); This will remove the hamburger icon on toolbar completely.

How do I hide the menu bar icon in Android?

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.


1 Answers

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);
    }
}); 
like image 81
darkprince92 Avatar answered Sep 18 '22 15:09

darkprince92