android - Up navigation not appearing for single activity app with multiple fragments -


i have android application has single main activity employs many fragments switch view. i'm not sure if that's right way it, have inherited project , avoid doing major refactors changing fragments activities or that.

according android documentation, looks calling setdisplayhomeasup(bool) function should display button default:

set whether home should displayed "up" affordance. set true if selecting "home" returns single level in ui rather top level or front page.

the main issue when use function:

actionbar.setdisplayhomeasupenabled(true); 

it not set button opens navigation drawer instead turn 'up' button. removes 'hamburger' ic_drawer icon side. navigation drawer still opens.

here custom code navigationdrawerfragment (i copy+pasted exact file when create new application navigation drawer within android studio):

navigationdrawerfragment.java

@override public view oncreateview(layoutinflater inflater, viewgroup container,                          bundle savedinstancestate) {     super.oncreateview(inflater, container, savedinstancestate);      mdrawerlistview = (listview) inflater.inflate(             r.layout.fragment_navigation_drawer, container, false);     mdrawerlistview.setonitemclicklistener(new adapterview.onitemclicklistener() {         @override         public void onitemclick(adapterview<?> parent, view view, int position, long id) {             selectitem(position);         }     });      populateappdrawerlist();     return mdrawerlistview; }  public void populateappdrawerlist() {     list<appoption> allapps = getallapps();     list<appoption> filteredapps = new arraylist<appoption>();      (int = 0; < allapps.size(); i++) {         if (allapps.get(i).getlaunchable()) {             filteredapps.add(allapps.get(i));         }     }       navdrawerlistadapter adapter = new navdrawerlistadapter(filteredapps, mainactivity.getinstance());     mdrawerlistview.setadapter(adapter);     mdrawerlistview.setitemchecked(mcurrentselectedposition, true); } 

then, have other fragments extend 'baseappfragment', contains following:

baseappfragment.java

public class baseappfragment extends fragment {

@override public void onstart() {     super.onstart();      mainactivity.getinstance().onsectionattached(this); }  @override public void onattach(activity activity) {     super.onattach(activity); } } 

this allows me change title on action bar in 1 single area , set whether or not should have button set default.

mainactivity.java

public void onsectionattached(android.app.fragment fragment) { class fragmenttype = fragment.getclass();

    actionbar actionbar = getactionbar();      mnavigationdrawerfragment.populateappdrawerlist();     if (fragmenttype != null) {         if (fragmenttype.equals(authenticationfragment.class)) {             actionbar.setdisplayhomeasupenabled(false);             mtitle = "login";         } else if (fragmenttype.equals(myoptionsfragment.class)) {             actionbar.setdisplayhomeasupenabled(false);             mtitle = "my options";         } else if (fragmenttype.equals(glauthenticationfragment.class)) {             actionbar.setdisplayhomeasupenabled(false);             mtitle = "login";         } else if (fragmenttype.equals(initialloginfragment.class)) {             actionbar.setdisplayhomeasupenabled(false);             mtitle = "login";         } else if (fragmenttype.equals(loginfragment.class)) {             actionbar.setdisplayhomeasupenabled(false);             mtitle = "login";         } else if (fragmenttype.equals(dailyoverviewfragment.class)) {             actionbar.setdisplayhomeasupenabled(true);             mtitle = "overview";         } else if (fragmenttype.equals(singlecomponentfragment.class)) {             actionbar.setdisplayhomeasupenabled(true);             singlecomponentfragment singlecomponentfragment = (singlecomponentfragment) fragment;              if (singlecomponentfragment != null && singlecomponentfragment .mcomponent != null) {                 mtitle = string.format("back day %s", singlecomponentfragment.mcomponent.getday() + "");             }             else {                 mtitle = "";             }         } else if (fragmenttype.equals(singledayoverviewfragment.class)) {             actionbar.setdisplayhomeasupenabled(true);             mtitle = "back overview";         }      }      actionbar.settitle(mtitle); } 

the title setting works , there no errors when setdisplayhomeasupenabled(true) called, still shows no button. know right not setting type of fragment navigation hierarchy other addtobackstack(null) call in fragment transaction, still seems code should enough have button replace navigation drawer button.

the problem navigation drawer icon hijacks indicator. in terms of view in action bar displaying icon, navigation drawer icon is also icon. why need call actionbar.setdisplayhomeasupenabled(true); navigation drawer icon show.

to fix this, need use actionbardrawertoggle#setdrawerindicatorenabled(false). replace navigation drawer icon icon. documentation method:

when indicator disabled, actionbar revert displaying home-as-up indicator provided activity's theme in android.r.attr.homeasupindicator attribute instead of animated drawer glyph.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -