How to set backarrow instead of hamburger icon for only one single fragment?

I replaced all the hamburger icons from all the slices using the code below in MainActivity.

 toggle.setDrawerIndicatorEnabled(false);
 toggle.setHomeAsUpIndicator(R.drawable.leftarrow);

Now I want this backarrow to be in only one fragment, and the rest of the fragments should have a hamburger icon. The fragment in which I need the back arrow is the one that is redirected from another fragment to onclick some data in cardview. I need to set the backarrow on the toolbar to the place of the hamburger icon to go to the previous fragment containing the map. I can’t solve it.

+4
source share
3 answers

Try it like this

Harmburger , , fragment onCreateView Method. , . , ActionBarToggle

ActivityDashboardBinding activityDashboardBinding = DashboardActivity.getActivityDashboardBinding();

ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(getActivity(),
activityDashboardBinding.drawerLayout, activityDashboardBinding.toolbar,
        R.string.navigation_drawer_open, R.string.navigation_drawer_close);

toggle.setDrawerIndicatorEnabled(false);
toggle.setHomeAsUpIndicator(R.drawable.ic_arrow_back);

: Harmburger back_arrow fragment fragment . fragment.

+5

. .

0

I think you should put the hamburger icon in the main action and change it in onCreateView in the desired fragment ...

0
source

Source: https://habr.com/ru/post/1675122/


All Articles