3 line icon is not animating into a smaller image in Navigation Drawer

故事扮演 提交于 2019-12-12 12:09:40

问题


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

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

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/19829455/3-line-icon-is-not-animating-into-a-smaller-image-in-navigation-drawer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!