A blog for technology, SEO tips, website development and open source programming.

Show and Hide ActionBar on Android code

0 805

The action bar is a window feature that identifies the user location, and provides user actions and navigation modes. Using the action bar offers your users a familiar interface across applications that the system gracefully adapts for different screen configurations.The post will demonstrate you how you can show or hide the ActionBar programatically with JAVA.

Example:

package com.panayiotisgeorgiou.androidshowhideactionbar;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button buttonToggleActionBar = new Button(this);
buttonToggleActionBar.setText(“Toggle ActionBar”);
setContentView(buttonToggleActionBar);

buttonToggleActionBar.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View arg0) {
if(getActionBar().isShowing()){
getActionBar().hide();
}else{
getActionBar().show();
}
}});
}
}

Leave a Reply

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More