Turn On/Off Action Bar
ActionBar on Android
3.0 (API level 11) is a window feature that identifies the application and user
location, and provides user actions and navigation modes.
To turn it on/off programmatically, call ActionBar.show() and ActionBar.hide().
Example:
To turn it on/off programmatically, call ActionBar.show() and ActionBar.hide().
Example:
package com.exercise.AndroidActionBar;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class AndroidActionBarActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button showActionBar = (Button)findViewById(R.id.showactionbar);
Button hideActionBar = (Button)findViewById(R.id.hideactionbar);
showActionBar.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
ActionBar actionBar = getActionBar();
actionBar.show();
}});
hideActionBar.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
ActionBar actionBar = getActionBar();
actionBar.hide();
}});
}
}
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class AndroidActionBarActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button showActionBar = (Button)findViewById(R.id.showactionbar);
Button hideActionBar = (Button)findViewById(R.id.hideactionbar);
showActionBar.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
ActionBar actionBar = getActionBar();
actionBar.show();
}});
hideActionBar.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
ActionBar actionBar = getActionBar();
actionBar.hide();
}});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/showactionbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Show Action Bar" />
<Button
android:id="@+id/hideactionbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hide Action Bar" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/showactionbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Show Action Bar" />
<Button
android:id="@+id/hideactionbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hide Action Bar" />
</LinearLayout>
No comments:
Post a Comment