Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide actionbar on touch android

I want to hide the top actionbar that I have as an overlay on touch and then show it again on another touch. Somehow I should probably add an onTouchListener to something but how? The event should only be handled when its not consumed by other handlers so that my multitouch will still work when I slide to change image etc. Thanks.

like image 568
TutenStain Avatar asked Sep 11 '26 22:09

TutenStain


1 Answers

Something like this should work (not tested code - so take with grain of salt)

Basically, override onTouch, and call its super method as to not lose functionality. Check if its consumed, else toggle or whatever to show/hide action bar.

Boolean showBar = true; // Global variable

@Override
public boolean onTouch(View v, MotionEvent event) {
   Boolean result = super.onTouch(v,event);

   if(!result) // False - Not consumed event.
   {
       if(showBar) // Toggle action bar visiblity
          getActionBar().hide();
       else
          getActionBar().show();

       showBar = !showBar;
   }
   return result;   
}
like image 104
IAmGroot Avatar answered Sep 14 '26 11:09

IAmGroot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!