android - how to use toolbar(humburger icon) as backstack navigation -


i have navigate fragment mainactivity , if have more 1 fragment in activity, need navigate 1 one using toolbar(humburger icon).

enter image description here

in fragment hosting toolbar, call activity backpress:

@override     public boolean onoptionsitemselected(menuitem item) {         switch (item.getitemid()) {             case android.r.id.home:                 getactivity().onbackpressed();                 break;         }          return true;     } 

to change icon arrow, in fragment:

        actionbar actionbar = getactivity().getsupportactionbar();         if (actionbar != null) {             // loading arrow drawable.             final drawable uparrow = getresources().getdrawable(r.drawable.abc_ic_ab_back_mtrl_am_alpha); // should work             actionbar.sethomeasupindicator(uparrow);             actionbar.setdisplayhomeasupenabled(true);             actionbar.sethomebuttonenabled(true);         } 

Comments

Popular posts from this blog

Lists in Python -

android - can not access to progress bar in an other activity -

html - Not able to access next element of an array javascript -