Materialdrawer: setDisplayHomeAsUpEnabled(true) goes nowhere

Created on 28 Feb 2015  ·  5Comments  ·  Source: mikepenz/MaterialDrawer

I've called setDisplayHomeAsUpEnabled(true) and the arrow is showing, but it goes no where.

How can I do this

thanks.

question

Most helpful comment

First you need to initialize the toolbar :

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

setSupportActionBar(toolbar);

then call the back button from actionBar :

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

getSupportActionBar().setDisplayShowHomeEnabled(true);

@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}

All 5 comments

I achieved the same by adding the following line in Manifest file
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />

Please suggest me if there is another way to do so.

@vishnudbimcs you mean the drawer toggle? the library itself provided basic drawer toggle functionality. you can also get the object back from the result.

This library handles the MaterialDrawer and just basic stuff around it. So for special cases with the Toolbar or the ActionBarToggler just implement it as you would if you create a normal application. ;)

Hello
I have an activity A with the Drawer and inside it I inflate a fragment A.
The drawer has .withActionBarDrawerToggle(true) and I haven't set the getSupportActionBar().setDisplayHomeAsUpEnabled(true) on the activity
Then, inside the Activity A y replace the fragment A by the fragment B, and I want to show the "backbutton" instead of the drawer toggle, after inflating the fragment B I do:

result.getActionBarDrawerToggle().setDrawerIndicatorEnabled(false);
 getSupportActionBar().setDisplayHomeAsUpEnabled(true);

And the backbutton is showed, however if I press it, it doesn't do anything. I have also made the Activity Override the OnbackPressed:

 @Override
  public void onBackPressed() {
}

But it is never hit.
I also have added onOptionsItemselected, but again nothing happens.

So I tested more things.
1) I removed the Drawer, and just use the

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Results: Back button on Fragment A and B and it works.

2) Using the drawer, but NOT changing the result.getActionBarDrawerToggle().setDrawerIndicatorEnabled(false);
when loading Fragment B
Result: The Hamburguer icon on Fragment A and B

3) Setting getSupportActionBar().setDisplayHomeAsUpEnabled(true); at the init of the Application,
and result.getActionBarDrawerToggle().setDrawerIndicatorEnabled(false); when loading the Fragment B
Result: hamburguer on Fragment A, nothing show on Fragment B

I don't know what is happening here...

@gpulido please read the following regarding this behavior

https://github.com/mikepenz/MaterialDrawer/issues/65

Thanks

First you need to initialize the toolbar :

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

setSupportActionBar(toolbar);

then call the back button from actionBar :

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

getSupportActionBar().setDisplayShowHomeEnabled(true);

@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

meness picture meness  ·  3Comments

jehad-suliman picture jehad-suliman  ·  3Comments

oleynikd picture oleynikd  ·  4Comments

ghost picture ghost  ·  3Comments

wayne1203 picture wayne1203  ·  3Comments