i'm trying toggle show/hide action bar on user click on activity, i've implemented functionality in activity:
@override public boolean dispatchtouchevent(motionevent ev) { log.d("action bar", "triggered"); super.dispatchtouchevent(ev); actionbar actionbar = getsupportactionbar(); actionbar.hide(); if (actionbar.isshowing()) { actionbar.hide(); } else { actionbar.show(); } return true; }
however, problem when clicked on activity, action bar gets hidden shown again. i've added logging , seems method triggered twice, why so?
i think dispatchtouchevent might called 2 time on touch down , action take 1 boolean flag , check flag value before showing action bar :
private boolean ismanuallyhideshownactionbar; @override public boolean dispatchtouchevent(motionevent ev) { super.dispatchtouchevent(ev); actionbar actionbar = getsupportactionbar(); if(!ismanuallyhideshownactionbar){ if (actionbar.isshowing()) { actionbar.hide(); } else { actionbar.show(); } ismanuallyhideshownactionbar = true; }else{ ismanuallyhideshownactionbar = false; } return true; }
Comments
Post a Comment