5

徽标旁边的小图标(指示器或 3 行)不会变小。

我想要的是这个 --> 此图像没有动画,当我单击应用程序的徽标时,抽屉已打开,但图像未动画成更小的图像,这表明抽屉当前已打开。

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

2 回答 2

5

请确保将此行放入您声明 ActionBarDrawerToggle 的代码中:

mDrawerLayout.setDrawerListener(mDrawerToggle);

如您在此示例中所见:

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

如果您忘记将抽屉监听器添加到抽屉布局中,它不会为您的抽屉图标设置动画。

于 2014-01-27T20:34:26.977 回答
1

尽管我在使用SherlockNavigationDrawer时遇到了这个问题,但它可能对某人有所帮助:确保您不要忘记在覆盖抽屉的方法(onDrawerOpened/Closed)中调用 super。

于 2014-02-09T22:29:18.057 回答