我遇到了問題。我也有漢堡包圖標和後退箭頭。漢堡正在完美地工作,但不是後退箭頭。它像漢堡一樣工作,打開和關閉抽屜菜單。後退箭頭正在關閉抽屜菜單,而不是後退
下面是一個代碼:
@Override
public void onDrawerClosed(View drawerView) {
hideKeyboard();
super.onDrawerClosed(drawerView);
}
@Override
public void onDrawerOpened(View drawerView) {
hideKeyboard();
super.onDrawerOpened(drawerView);
}};
mDrawerToggle.setDrawerIndicatorEnabled(true);
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
pager.setVisibility(View.VISIBLE);
tabLayout.setVisibility(View.VISIBLE);
mDrawerToggle.setDrawerIndicatorEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mDrawerToggle.syncState();
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbarInner);
toolbar.setNavigationOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
openAndCloseDrawer();
}
});
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
openAndCloseDrawer();
return true;
}
return false;
}
});
public void customizeActionBarWithBack(String string)
{
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbarInner);
toolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000));
toolbar.setTitle(string);
setDisplayHomeAsUpEnabled(true, R.drawable.abc_ic_ab_back_material);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
toolbar.setNavigationOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
customizeActionBar();
}
});
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case android.R.id.home:
recreate();
customizeActionBar();
return true;
}
return false;
}
});
}
哪裏出了問題?請幫助我們!
Where把它放?因爲我得到'方法不會覆蓋超類中的方法'並且onBackPressed()從未使用 –
您可以使用接口實現此任務,在活動中實現接口並在片段中定義它然後您可以通過回調函數處理它 – Farhan
@ DawidWalczyk是您的活動擴展AppCompatActivity?或者你在使用片段? – cuoka