5

The small icon(indicator or 3 line) beside the logo, is not changing into a smaller one.

What i want is this --> this image is not animating, When I click the apps' logo the drawer is opened but the image is not animated into a more smaller image which is an indicator that the drawer is currently opened.

gABar.get().setDisplayHomeAsUpEnabled(true);

 mDrawerToggle = new ActionBarDrawerToggle(
        getActivity(),                  /* host Activity */
        mDrawerLayout.get(),         /* DrawerLayout object */
        R.drawable.ic_drawer2,  /* nav drawer image to replace 'Up' caret */
        R.string.drawer_open,  /* "open drawer" description for accessibility */
        R.string.drawer_close  /* "close drawer" description for accessibility */
        ) {
    @Override
    public void onDrawerClosed(View view) {
        getActivity().getActionBar().setTitle(mTitle);
        getActivity().invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()

        Log.d("onDrawerClosed", "inside");
    }

    @Override
    public void onDrawerOpened(View drawerView) {
        getActivity().getActionBar().setTitle(mDrawerTitle);
        getActivity().invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
    }

};

@Override
public boolean onOptionsItemSelected(MenuItem item) 
{
    int id = item.getItemId();
    Log.d("item ID : ", "onOptionsItemSelected Item ID" + id);
    if (id == android.R.id.home) {


        return true;

    } else {
        return super.onOptionsItemSelected(item);
    }
}
rahstame
  • 2,148
  • 4
  • 23
  • 53
  • First of all, try to put `@Override` on your `onDrawerClosed` and `onDrawerOpened`. Second thing be sure that you are calling: `mDrawerLayout.setDrawerListener(mDrawerToggle);` or something similar to this. – hardartcore Nov 07 '13 at 08:57
  • @Android-Developer, I have those two on my codes. – rahstame Nov 11 '13 at 05:18
  • So you should add some more aditional code. – hardartcore Nov 11 '13 at 08:55
  • @Android-Developer ..can you share your possible resolve to this, been trying this, but can't see how to really resolve this. tried experimenting already and did my research. I think, just a few encountered this problem – rahstame Nov 11 '13 at 09:14
  • Did you tried : http://stackoverflow.com/questions/19724567/how-to-add-menu-indicator-next-to-action-bars-app-icon/19724694#19724694 ? Check the `mDrawerToggle.syncState()` part and be sure to add this to your code too. – hardartcore Nov 11 '13 at 09:18
  • @Android-Developer . thanks. I have this on my code as well. I followed the steps on it before but still the same. – rahstame Nov 11 '13 at 09:23
  • Post the whole code of your Fragment, so I can see it, because it looks ok to me checking this code. – hardartcore Nov 11 '13 at 09:32

2 Answers2

5

please ensure you put this line into your code where you declared your ActionBarDrawerToggle:

mDrawerLayout.setDrawerListener(mDrawerToggle);

as you can see in this example:

public class MyActivity extends ActionBarActivity  {

    private DrawerLayout mDrawerLayout;
    private ListView mDrawerList;
    private ActionBarDrawerToggle mDrawerToggle;
    private String[] menuitems;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        mDrawerLayout   = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList     = (ListView) findViewById(R.id.left_drawer);
        menuitems   = getResources().getStringArray(R.array.optionsname);

        MyDrawerAdapter draweradapter = new  MyDrawerAdapter(getApplicationContext(), menuitems);
        mDrawerList.setAdapter(draweradapter);

        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_navigation_drawer, R.string.drawer_open, R.string.drawer_close) {

            public void onDrawerClosed(View view) {
                invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                invalidateOptionsMenu();
            }

            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                super.onDrawerSlide(drawerView, slideOffset);
                mDrawerLayout.bringToFront();
                mDrawerLayout.bringChildToFront(drawerView);
                mDrawerLayout.requestLayout();
                mDrawerLayout.invalidate();
            }
        };

        mDrawerLayout.setDrawerListener(mDrawerToggle);

        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setIcon(new ColorDrawable(0x00000000));
        getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0xffffffff));
    }
}

if you forget to add the drawerlistener to the drawerlayout it wont animate your drawer icon.

user2832084
  • 51
  • 2
  • 3
  • welcome to stackoverflow! this is a little terse, can you expand a little bit? such as showing where this line goes in the code? – Corley Brigman Jan 27 '14 at 20:55
  • The following line must come after the DrawerToggle is instantiated mDrawerLayout.setDrawerListener(mDrawerToggle); – nathanielwolf Feb 26 '14 at 10:09
  • You also should call the syncState() method from the onDrawerClosed(View) and onDrawerOpened(View) methods of the ActionBarDrawerToggle. – dazed Nov 10 '16 at 16:05
1

Although I had this problem with SherlockNavigationDrawer, maybe it help someone: ensure you don't forgot to call super in overriden drawer's methods (onDrawerOpened/Closed).

sendevent
  • 212
  • 1
  • 8