我按照此处的教程http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/来实现滑块菜单。
使用那里的代码我得到警告不推荐使用ActionBarDrawerToggle。所以我替换
import android.support.v4.app.ActionBarDrawerToggle;
到
import android.support.v7.app.ActionBarDrawerToggle;
同时更改行
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
)
到
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
)
并且
设置抽屉监听器
mDrawerLayout.setDrawerListener(mDrawerToggle);
和onclick监听器实现类似
private class SlideMenuClickListener implements
ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// display view for selected nav drawer item
displayView(position);
}
}
但是当我点击菜单项时似乎没有调用该事件,可能是什么问题?