Replace navigation drawer when opening fragment

0

This is my scenario, I have Activity with Navigation Drawer implemented, and in that Activity contains a container where Fragments is called.

My problem is this: I want the Navigation Drawer burger icon to be replaced with a Back Arrow when opening a certain Fragment and works just like a back button, and when I close this Fragment , the icon Navigation Drawer burger come back.

I used getSupportActionBar().setDisplayHomeAsUpEnabled(true) when calling Fragment on Activity , Back Arrow appeared but instead of returning, it opens navigation drawer .

I also gave Override in OnOptionItemSelected of Activity , but to no avail.

   @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId() == android.R.id.home){
            onBackPressed();
        }
        return super.onOptionsItemSelected(item);
    }

Can anyone give me a light on how to implement this back button without having to call a Activity instead of Fragment ?

    
asked by anonymous 28.11.2018 / 17:59

0 answers