Show and Hide ActionBar using Java code
Example Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | package com.example.androidtoggleactionbar; 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(); } }}); } } |
Android Coding: Show and Hide ActionBar using Java code