diff --git a/samples/ApiDemos/AndroidManifest.xml b/samples/ApiDemos/AndroidManifest.xml
index 48b7f233e..ca4d53eef 100644
--- a/samples/ApiDemos/AndroidManifest.xml
+++ b/samples/ApiDemos/AndroidManifest.xml
@@ -652,6 +652,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/ApiDemos/res/menu/actions.xml b/samples/ApiDemos/res/menu/actions.xml
new file mode 100644
index 000000000..d148ac915
--- /dev/null
+++ b/samples/ApiDemos/res/menu/actions.xml
@@ -0,0 +1,44 @@
+
+
+
diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml
index 700740dda..265f9dd9e 100644
--- a/samples/ApiDemos/res/values/strings.xml
+++ b/samples/ApiDemos/res/values/strings.xml
@@ -530,6 +530,20 @@
Speak!
Results:
+
+
+
+
+ App/Action Bar/Action Bar Mechanics
+ App/Action Bar/Action Bar Usage
+
+ Search
+ Add
+ Edit
+ Share
+ Zoom
+ Save
+
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/ActionBarMechanics.java b/samples/ApiDemos/src/com/example/android/apis/app/ActionBarMechanics.java
new file mode 100644
index 000000000..e4797806c
--- /dev/null
+++ b/samples/ApiDemos/src/com/example/android/apis/app/ActionBarMechanics.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.android.apis.app;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.Window;
+import android.widget.Toast;
+
+/**
+ * This demonstrates the basics of the Action Bar and how it interoperates with the
+ * standard options menu. This demo is for informative purposes only; see ActionBarUsage for
+ * an example of using the Action Bar in a more idiomatic manner.
+ */
+public class ActionBarMechanics extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // The Action Bar is a window feature. The feature must be requested
+ // before setting a content view. Normally this is set automatically
+ // by your Activity's theme in your manifest. The provided system
+ // theme Theme.WithActionBar enables this for you. Use it as you would
+ // use Theme.NoTitleBar. You can add an Action Bar to your own themes
+ // by adding the element - true
+ // to your style definition.
+ getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Menu items default to never show in the action bar. On most devices this means
+ // they will show in the standard options menu panel when the menu button is pressed.
+ // On xlarge-screen devices a "More" button will appear in the far right of the
+ // Action Bar that will display remaining items in a cascading menu.
+ menu.add("Normal item");
+
+ MenuItem actionItem = menu.add("Action Button");
+
+ // Items that show as actions should favor the "if room" setting, which will
+ // prevent too many buttons from crowding the bar. Extra items will show in the
+ // overflow area.
+ actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+
+ // Items that show as actions are strongly encouraged to use an icon.
+ // These icons are shown without a text description, and therefore should
+ // be sufficiently descriptive on their own.
+ actionItem.setIcon(android.R.drawable.ic_menu_share);
+
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ Toast.makeText(this, "Selected Item: " + item.getTitle(), Toast.LENGTH_SHORT).show();
+ return true;
+ }
+}
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/ActionBarUsage.java b/samples/ApiDemos/src/com/example/android/apis/app/ActionBarUsage.java
new file mode 100644
index 000000000..9657558cd
--- /dev/null
+++ b/samples/ApiDemos/src/com/example/android/apis/app/ActionBarUsage.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.example.android.apis.app;
+
+import android.app.Activity;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.widget.Toast;
+
+import com.example.android.apis.R;
+
+/**
+ * This demonstrates idiomatic usage of the Action Bar. The theme Theme.WithActionBar
+ * is specified for this activity in AndroidManifest.xml and a menu resource is used
+ * to populate the menu data itself. If you'd like to see how these things work under
+ * the hood, see ActionBarMechanics.
+ */
+public class ActionBarUsage extends Activity {
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.actions, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ Toast.makeText(this, "Selected Item: " + item.getTitle(), Toast.LENGTH_SHORT).show();
+ return true;
+ }
+
+ // This method is specified as an onClick handler in the menu xml and will
+ // take precedence over the Activity's onOptionsItemSelected method.
+ // See res/menu/actions.xml for more info.
+ public void onSearch(MenuItem item) {
+ Toast.makeText(this, "Searching...", Toast.LENGTH_SHORT).show();
+ }
+}