2

I can't have the Drawer Indicator display. Currently I have either nothing or the "<" at the top left corner of the screen depending of the actionBar settings. But I want the Drawer Indicator of the Nagivation Drawer instead.

I use :

  • v4.widget.DrawerLayout
  • v7.app.ActionBarDrawerToggle
  • but android.app.ActionBar (not the support 7 one).

Here is snippet of the code :

@Override
protected void onCreate(Bundle savedInstanceState)
{
    actionBar.setDisplayHomeAsUpEnabled(true); 
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayShowHomeEnabled(true);
    //I tried all combinations unsuccessfully
    ....
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerLV = (ListView) findViewById(R.id.left_drawer);
    drawer_Linearlayout = (LinearLayout) findViewById(R.id.drawer_Linearlayout);

    drawerLV.setAdapter(new ArrayAdapter<String>(
            this,
            R.layout.layout_main_drawer_list_item,
            mDrawerItems));

    drawerLV.setOnItemClickListener(new ListView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
    });

    drawerToggle = new ActionBarDrawerToggle(this, drawer, R.string.drawer_open,R.string.drawer_close) {
        @Override
        public void onDrawerClosed(View view) {
            actionBar.setTitle(mTitle);
    }
        @Override
        public void onDrawerOpened(View drawerView) {
            actionBar.setTitle(mDrawerTitle);
        }
    };
    drawerToggle.setDrawerIndicatorEnabled(true);
    drawer.setDrawerListener(drawerToggle);
}
u2gilles
  • 6,888
  • 7
  • 51
  • 75
  • possible duplicate of [display back button on action bar - android](http://stackoverflow.com/questions/15686555/display-back-button-on-action-bar-android) – Abdallah Alaraby Nov 07 '14 at 16:46

3 Answers3

1

I eventually fixed my problem. I forgot to add the following callback in my Acticity :

protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    drawerToggle.syncState();
}

By the way, Lollipop upgrade of v7.app.ActionBarDrawerToggle adds a nice effect when the navigation drawer is opening or closing. I recommend it.

u2gilles
  • 6,888
  • 7
  • 51
  • 75
0

I think you also must specify android.R.id.home it in the onOptionsItemSelected to make the back button visible :

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            //the onClick for your back button
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

And you just need to use actionBar.setDisplayHomeAsUpEnabled(true);

UPDATE :

Just did a quick googling, take a look at this :

Display back button on action bar

Try my answer. I think it will solve your problem.

Community
  • 1
  • 1
Blaze Tama
  • 10,828
  • 13
  • 69
  • 129
  • Thanks but I can easily have the back button. What I want is to replace it by the Drawer Indicator. – u2gilles Nov 07 '14 at 16:31
  • @u2gilles Sorry..you said this in your question : "I have either nothing or the "<" at the top left corner of the screen." – Blaze Tama Nov 07 '14 at 16:33
0

Sorry for my previous answer, I misread it. Think this is what you need:

mDrawerToggle = new ActionBarDrawerToggle(
        this,                             
        mDrawerLayout,                 
        R.drawable.ic_drawer, /* The image drawable you're missing */          
        R.string.navigation_drawer_open,  
        R.string.navigation_drawer_close  

The image is custom, also known as the hamburger.

Doppie
  • 95
  • 1
  • 8
  • 1
    This parameter does not exist any more in android.support.v7.app.ActionBarDrawerToggle; And android.support.v4.app.ActionBarDrawerToggle is now depreciated. Anyway, I also tried in android.support.v4.app.ActionBarDrawerToggle and it was also not working. – u2gilles Nov 07 '14 at 20:51