我打算在打开和关闭导航抽屉时调用一些方法.我怎么能听它(比如按钮的onclick听众)?
我知道我们可以检查(mDrawer.isDrawerOpen(Gravity.LEFT)
)或((mDrawer.isDrawerClose(Gravity.LEFT))
).
提前致谢.
是的,有四种抽象方法可以用作听众
public abstract void onDrawerClosed (View drawerView) public abstract void onDrawerOpened (View drawerView) public abstract void onDrawerSlide (View drawerView, float slideOffset) public abstract void onDrawerStateChanged (int newState)
可以像这样使用
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { public void onDrawerClosed(View view) { super.onDrawerClosed(view); // Do whatever you want here } public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); // Do whatever you want here } }; mDrawerLayout.addDrawerListener(mDrawerToggle);
复制自http://developer.android.com/reference/android/support/v4/widget/DrawerLayout.DrawerListener.html
UPDATE
setDrawerListener
方法在API级别24.1.0中已弃用.所以用addDrawerListener()