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

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -