How to show / hide the action bar when clicked

When the user clicks anywhere on the screen, I want the action bar to be hidden, and when I click it again, it should appear again.

I know that there is something called actionbar.hide (); and show, but can you please help me how to implement it? :)

+4
source share
2 answers

Just hide () :

getActionBar().hide(); 

when you want to hide it and use show () :

 getActionBar().show() 

when you want to show it. What about that.

Remember that if you use View.SYSTEM_UI_FLAG_FULLSCREEN , this will not work correctly.

+14
source

Try it. you have the option to call the hide or show method and as per your suggestion

 public class AbstractActivity Activity { private boolean showActions = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActionBar bar = getSupportActionBar(); if (bar != null) { bar.setHomeButtonEnabled(true); bar.setDisplayShowHomeEnabled(true); } } @Override public boolean onCreateOptionsMenu(Menu menu) { return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case android.R.id.home: return true; default: // Nothing to do here return super.onOptionsItemSelected(item); } } private void handleActionBarTitle(boolean show) { ActionBar actionBar = getSupportActionBar(); if (actionBar == null) { return; } actionBar.setDisplayShowTitleEnabled(show); } protected void disableActions() { this.showActions = false; } protected void enableActions() { this.showActions = true; } protected void hideActionBarTitle() { handleActionBarTitle(false); } protected boolean showActions() { return showActions; } protected void showActionTitle() { handleActionBarTitle(true); } 

Your activity just needs to expand this AbstractActivity

+1
source

All Articles