ActionBar的移除与显示

activity_main.xml:



    

ActionBarHiddenActivity.java:

package com.example.demoactionbar;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class ActionBarHiddenActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		final ActionBar bar = getActionBar();
		final Button button = (Button)findViewById(R.id.button);
		button.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View view) {
				if(bar.isShowing()){
					bar.hide();
					button.setText("显示动作栏");
				}else{
					bar.show();
					button.setText("隐藏动作栏");
				}

				
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}

AndroidManifest.xml:




    

    
        
            
                

                
            
        
    




你可能感兴趣的:(android)