Search code examples
androiddrawerlayoutindicator

Drawer Indicator does not show


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);
}

Solution

  • 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.