android - Disable ActionBarDrawerToggle's drawer indicator, but keep the hamburger icon -


in main activity i'm getting references drawerlayout , toolbars this:

    //set toolbar     toolbar = (toolbar) findviewbyid(r.id.toolbar);     setsupportactionbar(toolbar);      //set navigation drawer     drawer = (drawerlayout) findviewbyid(r.id.drawer_layout);     hamburger = new actionbardrawertoggle(             this, drawer, toolbar, r.string.navigation_drawer_open, r.string.navigation_drawer_close);     drawer.setdrawerlistener(hamburger);     hamburger.syncstate(); 

in 1 of fragments, want disable 1) swiping open nav drawer , 2) hamburger/toggle button toggle nav drawer opening

currently, i'm doing this:

mainactivity = (mainactivity)getactivity(); mainactivity.drawer.setdrawerlockmode(drawerlayout.lock_mode_locked_closed); mainactivity.hamburger.setdrawerindicatorenabled(false); mainactivity.hamburger.syncstate(); 

swiping correctly handled - no longer opens drawer.

the hamburger icon has disappeared though. ideally, want hamburger icon remain on screen, sit in disabled state doesn't when clicked. there alternative setdrawerindicatorenabled work way?

the simplest way set drawerarrowdrawable toggle's indicator, , enable/disable drawer indicator usual.

after you've initialized actionbardrawertoggle, call:

hamburger.sethomeasupindicator(new drawerarrowdrawable(toolbar.getcontext())); 

drawerarrowdrawable actionbardrawertoggle uses animation, , default state hamburger. when disable drawer indicator, switches indicator, doesn't receive drawer opening/closing calls, sits in default state. re-enabling drawer indicator switches toggle, drawer events, animation re-enabled well.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -