Action bar Back button not working

前端 未结 13 1805
再見小時候
再見小時候 2020-12-01 03:13

with the help of these Android Docs.I am trying to do a action bar Back button.I get an Action Bar Back Button like these below image:

13条回答
  •  旧巷少年郎
    2020-12-01 03:50

    Try like

    First of all you need to use addToBackStack() before commit() for Fragments

    @Override
         public boolean onOptionsItemSelected(MenuItem item) {
             switch (item.getItemId()) {
             // Respond to the action bar's Up/Home button
             case android.R.id.home:
                 if(getSupportFragmentManager().getBackStackEntryCount()>0)
                    getSupportFragmentManager().popBackStack();
                 return true;
             }
             return super.onOptionsItemSelected(item);
         } 
    

提交回复
热议问题