Search code examples
javaandroidnavigation-drawersearchview

Android ActionBar custom view and NavigationDrawer


I just ran into some problem with my project main activity. I have a SherlockFragmentActivity with a NavigationDrawer and a SearchView on the ActionBar with a custom view. The problem is when I type a query on my SearchView, I can do my search and all works fine, but when I close the SearchView, my ActionBar custom view and NavigationDrawer toggle disappear from the ActionBar.

Here is the graphical problem enter image description here

Here is my NavigationDrawer

private void initialiseDrawer(){
    this.drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
    this.drawerList = (ListView)findViewById(R.id.navigation_drawer);
    this.drawerAdapter = new NavigationDrawerAdapter(MainActivity.this);
    this.drawerList.setAdapter(drawerAdapter);
    this.drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            handleDrawerSelectedPosition(position);
        }
    });

    //getSupportActionBar().setHomeButtonEnabled(true);
    this.drawerToggle = new ActionBarDrawerToggle(this, this.drawerLayout, R.drawable.drawer,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close){
        public void onDrawerOpened(View view){
            super.onDrawerOpened(view);
            hideMenu();
        }

        public void onDrawerClosed(View view){
            super.onDrawerClosed(view);
            showMenu();
        }
    };

    this.drawerLayout.setDrawerListener(drawerToggle);
    this.drawerToggle.syncState();
}

And this is how I set my ActionBar

private void showCustomActionBarView(){
    getSupportActionBar().setDisplayShowHomeEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setDisplayUseLogoEnabled(false);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setCustomView(R.layout.action_bar_layout);
}

What can I do to show my custom View and DrawerToggle after the SearchView has been dettached?


Solution

  • Well, I found my own answer here, I was using SherlockActionBar and the support libraries 4.0, I just removed the sherlock libraries and upated my support libraries to v7.21.03, implemented Toolbar and every issue went out, hope it helps somebody else than me