我在android中使用NavigationDrawer。其工作正常。現在我想更改NavigationDrawer後臺按鈕的圖像,所以我使用這個mDrawerToggle.setDrawerIndicatorEnabled(false);
它隱藏默認的後臺按鈕圖像。現在改變圖像使用這個mDrawerToggle.setHomeAsUpIndicator(R.mipmap.ic_launcher);
,但點擊自定義導航後退按鈕抽屜不工作。如何管理?導航抽屜後退按鈕單擊Android中的偵聽器
我的代碼是
public void setUp(int fragmentId, DrawerLayout drawerLayout, final Toolbar toolbar) {
containerView = getActivity().findViewById(fragmentId);
mDrawerLayout = drawerLayout;
mDrawerToggle = new ActionBarDrawerToggle(getActivity(), drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {
@Override
public void onDrawerOpened(View drawerView) {
is= false;
super.onDrawerOpened(drawerView);
getActivity().invalidateOptionsMenu();
}
@Override
public void onDrawerClosed(View drawerView) {
is= true;
super.onDrawerClosed(drawerView);
getActivity().invalidateOptionsMenu();
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, slideOffset);
}
};
mDrawerToggle.setHomeAsUpIndicator(R.mipmap.ic_launcher);
mDrawerToggle.setDrawerIndicatorEnabled(false);
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerLayout.post(new Runnable() {
@Override
public void run() {
mDrawerToggle.syncState();
}
});
}
嘗試看看這裏http://stackoverflow.com/questions/26582075/cannot-catch-toolbar-home-button-click-event – lubilis
只要把你的代碼在這裏..所以我可以糾正它.. –