diff --git a/docs/html/guide/topics/resources/menu-resource.jd b/docs/html/guide/topics/resources/menu-resource.jd index b2d6eb3445c9b..af56a6c5cabe6 100644 --- a/docs/html/guide/topics/resources/menu-resource.jd +++ b/docs/html/guide/topics/resources/menu-resource.jd @@ -122,12 +122,16 @@ Bar. A menu item can appear as an action item only when the activity includes an android.app.ActionBar} (introduced in API Level 11). Valid values:
| Value | Description |
|---|---|
ifRoom | Only place this item in the Action Bar if -there is room for it. |
ifRoom | Only place this item in the
+ Action Bar if there is room for it. If there is not room for all
+ the items marked "ifRoom", the items with the lowest
+ orderInCategory values are displayed as actions, and
+ the remaining items are displayed in the overflow menu. |
withText | Also include the title text (defined by {@code android:title}) with the action item. You can include this value along with one of the others as a flag set, by separating them with a pipe {@code |}. |
never | Never place this item in the Action Bar. |
never | Never place this item in the Action Bar. Instead, list the item in the Action Bar's overflow + menu. |
always | Always place this item in the Action Bar.
Avoid using this unless it's critical that the item always appear in the action
bar. Setting multiple items to always appear as action items can result in them overlapping
@@ -301,4 +305,4 @@ available only on Android 3.0 (API Level 11) and greater.
-
\ No newline at end of file
+
diff --git a/docs/html/images/training/appbar/appbar_basic.png b/docs/html/images/training/appbar/appbar_basic.png
new file mode 100644
index 0000000000000..bcac6f5a40eff
Binary files /dev/null and b/docs/html/images/training/appbar/appbar_basic.png differ
diff --git a/docs/html/images/training/appbar/appbar_basic_2x.png b/docs/html/images/training/appbar/appbar_basic_2x.png
new file mode 100644
index 0000000000000..3a6042d066ebd
Binary files /dev/null and b/docs/html/images/training/appbar/appbar_basic_2x.png differ
diff --git a/docs/html/images/training/appbar/appbar_sheets.png b/docs/html/images/training/appbar/appbar_sheets.png
new file mode 100644
index 0000000000000..74cefd909355c
Binary files /dev/null and b/docs/html/images/training/appbar/appbar_sheets.png differ
diff --git a/docs/html/images/training/appbar/appbar_sheets_2x.png b/docs/html/images/training/appbar/appbar_sheets_2x.png
new file mode 100644
index 0000000000000..81241100c186f
Binary files /dev/null and b/docs/html/images/training/appbar/appbar_sheets_2x.png differ
diff --git a/docs/html/images/training/appbar/appbar_with_button.png b/docs/html/images/training/appbar/appbar_with_button.png
new file mode 100644
index 0000000000000..356f2f4520ac3
Binary files /dev/null and b/docs/html/images/training/appbar/appbar_with_button.png differ
diff --git a/docs/html/images/training/appbar/appbar_with_button_2x.png b/docs/html/images/training/appbar/appbar_with_button_2x.png
new file mode 100644
index 0000000000000..1292b24f0a63d
Binary files /dev/null and b/docs/html/images/training/appbar/appbar_with_button_2x.png differ
diff --git a/docs/html/training/appbar/actions.jd b/docs/html/training/appbar/actions.jd
new file mode 100644
index 0000000000000..68483cafd6363
--- /dev/null
+++ b/docs/html/training/appbar/actions.jd
@@ -0,0 +1,154 @@
+page.title=Adding and Handling Actions
+page.tags="appbar","actionbar"
+helpoutsWidget=true
+trainingnavtop=true
+
+@jd:body
+
+
+
+
+
+
+
+
+
+
+
+
+Design Guide+Action Buttons ++ The app bar allows you to add buttons for user actions. This feature lets you + put the most important actions for the current context right at the + top of the app. For example, a photo browsing app might show share + and create album buttons at the top when the user is looking at + their photo roll; when the user looks at an individual photo, the app might + show crop and filter buttons. + + ++ Space in the app bar is limited. If an app declares more actions than can + fit in the app bar, the app bar send the excess actions to an + overflow menu. The app can also specify that an action should always + be shown in the overflow menu, instead of being displayed on the app bar. + + +
+
++ Figure 1. An app bar with a single action button and an + overflow menu. + + +Add Action Buttons+ +
+ All action buttons and other items available in the action overflow are
+ defined in an XML menu resource. To
+ add actions to the action bar, create a new XML file in your project's
+
+ Add an +<menu xmlns:android="http://schemas.android.com/apk/res/android" > + + <!-- "Mark Favorite", should appear as action button if possible --> + <item + android:id="@+id/action_favorite" + android:icon="@drawable/ic_favorite_black_48dp" + android:title="@string/action_favorite" + app:showAsAction="ifRoom"/> + + <!-- Settings, should always be in the overflow --> + <item android:id="@+id/action_settings" + android:title="@string/action_settings" + app:showAsAction="never"/> + +</menu> ++ +
+ The + The system uses the action's icon as the action button if the action is + displayed in the app bar. You can find many useful icons on the Material Icons page. + + +Respond to Actions+ +
+ When the user selects one of the app bar items, the system calls your
+ activity's {@link android.app.Activity#onOptionsItemSelected
+ onOptionsItemSelected()} callback method, and passes a {@link
+ android.view.MenuItem} object to indicate which item was clicked. In your
+ implementation of {@link android.app.Activity#onOptionsItemSelected
+ onOptionsItemSelected()}, call the {@link android.view.MenuItem#getItemId
+ MenuItem.getItemId()} method to determine which item was pressed. The ID returned
+ matches the value you declared in the corresponding + For example, the following code checks to see which action the user selected. + If the method does not recognize the user's action, it invokes the superclass + method: + + +
+@Override
+public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.action_settings:
+ // User chose the "Settings" item, show the app settings UI...
+ return true;
+
+ case R.id.action_favorite:
+ // User chose the "Favorite" action, mark the current item
+ // as a favorite...
+ return true;
+
+ default:
+ // If we got here, the user's action was not recognized.
+ // Invoke the superclass to handle it.
+ return super.onOptionsItemSelected(item);
+
+ }
+}
+
diff --git a/docs/html/training/appbar/index.jd b/docs/html/training/appbar/index.jd
new file mode 100644
index 0000000000000..144e99f2f525b
--- /dev/null
+++ b/docs/html/training/appbar/index.jd
@@ -0,0 +1,98 @@
+page.title=Adding the App Bar
+page.tags="appbar","actionbar"
+helpoutsWidget=true
+trainingnavtop=true
+startpage=true
+
+@jd:body
+
+
+
+
+
+
+
+Dependencies and prerequisites+
You should also read+ + ++ The app bar, also known as the action bar, is one of the most + important design elements in your app's activities, because + it provides a visual structure and interactive elements that are familiar to + users. Using the app bar makes your app consistent with other Android apps, + allowing users to quickly understand how to operate your app and have a great + experience. + The key functions of the app bar + are as follows: + + +
+
++ This class describes how to use the + v7 + appcompat support library's {@link + android.support.v7.widget.Toolbar} widget as an app bar. There are other ways + to implement an app bar—for example, some themes set up an {@link + android.app.ActionBar} as an app bar by default—but using the appcompat + {@link android.support.v7.widget.Toolbar} makes it easy to set up an app bar + that works on the widest range of devices, and also gives you room to + customize your app bar later on as your app develops. + + +Lessons+ +
+
+
+
+
+
+
+This lesson teaches you to+ + + +You should also read+ ++ In its most basic form, the action bar displays the title for the activity on + one side and an overflow menu on the other. Even in this simple + form, the app bar provides useful information to the users, and helps to give + Android apps a consistent look and feel. + + +
+Figure 1. An app bar with the app +title and overflow menu. + + + Beginning with Android 3.0 (API level 11), all + activities that use the default theme have an {@link android.app.ActionBar} + as an app bar. However, app bar features have gradually been added to the + native {@link android.app.ActionBar} over various Android releases. As a + result, the native {@link android.app.ActionBar} behaves differently + depending on what version of the Android system a device may be using. By + contrast, the most recent features are added to the support library's version + of {@link android.support.v7.widget.Toolbar}, and they are available on any + device that can use the support library. + + ++ For this reason, you should use the support library's {@link + android.support.v7.widget.Toolbar} class to implement your activities' app + bars. Using the support library's toolbar helps ensure that your app will + have consistent behavior across the widest range of devices. For example, the + {@link android.support.v7.widget.Toolbar} widget provides a material design experience on + devices running Android 2.1 (API level 7) or later, but the native action + bar doesn't support material design unless the device is running Android 5.0 + (API level 21) or later. + + +Add a Toolbar to an Activity+ +These steps describe how to set up a {@link android.support.v7.widget.Toolbar} +as your activity's app bar: + +
+ Your app now has a basic action bar. By default, the action bar contains just + the name of the app and an overflow menu. The options menu initially contains + just the Settings item. You can add more actions to the + action bar and the overflow menu, as described in Adding and Handling Actions. + + +Use App Bar Utility Methods+ ++ Once you set the toolbar as an activity's app bar, you have access to the + various utility methods provided by the + v7 + appcompat support library's {@link + android.support.v7.app.ActionBar} class. This approach lets you do a number of useful + things, like hide and show the app bar. + + ++ To use the {@link android.support.v7.app.ActionBar} utility methods, call the + activity's {@link + android.support.v7.app.AppCompatActivity#getSupportActionBar + getSupportActionBar()} method. This method returns a reference to an + appcompat {@link android.support.v7.app.ActionBar} object. + Once you have that reference, you can call any of the {@link + android.support.v7.app.ActionBar} methods to adjust the app bar. For example, + to hide the app bar, call {@link android.support.v7.app.ActionBar#hide + ActionBar.hide()}. + diff --git a/docs/html/training/appbar/up-action.jd b/docs/html/training/appbar/up-action.jd new file mode 100644 index 0000000000000..1336d207ff03f --- /dev/null +++ b/docs/html/training/appbar/up-action.jd @@ -0,0 +1,134 @@ +page.title=Adding an Up Action +page.tags="appbar","actionbar", "up" +helpoutsWidget=true +trainingnavtop=true + +@jd:body + +
+
+
+
+
+
+This lesson teaches you to+ +
See Also+ + + ++ Your app should make it easy for users to find their way back to the app's + main screen. One simple way to do this is to provide an Up + button on the app bar for all activities except the main one. When the user + selects the Up button, the app navigates to the parent + activity. + + ++ This lesson shows you how to add an Up button to an activity by + declaring the activity's parent in the manifest, and enabling the app bar's + Up button. + + +Declare a Parent Activity+ +
+ To support the up functionality in an activity, you need to declare the
+ activity's parent. You can do this in the app manifest, by setting an
+
+ The
+ For example, suppose your app has a main activity named
+ +<application ... > + ... + + <!-- The main/home activity (it has no parent activity) --> + + <activity + android:name="com.example.myfirstapp.MainActivity" ...> + ... + </activity> + + <!-- A child of the main activity --> + <activity + android:name="com.example.myfirstapp.MyChildActivity" + android:label="@string/title_activity_child" + android:parentActivityName="com.example.myfirstapp.MainActivity" > + + <!-- Parent activity meta-data to support 4.0 and lower --> + <meta-data + android:name="android.support.PARENT_ACTIVITY" + android:value="com.example.myfirstapp.MainActivity" /> + </activity> +</application> ++ + Enable the Up Button+ +
+ To enable the Up button for an activity that has a parent
+ activity, call the app bar's {@link
+ android.support.v7.app.ActionBar#setDisplayHomeAsUpEnabled
+ setDisplayHomeAsUpEnabled()} method. Typically, you would do this when the
+ activity is created. For example, the following {@link
+ android.app.Activity#onCreate onCreate()} method sets a {@link
+ android.support.v7.widget.Toolbar} as the app bar for
+
+@Override
+protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_my_child);
+
+ // my_child_toolbar is defined in the layout file
+ Toolbar myChildToolbar =
+ (Toolbar) findViewById(R.id.my_child_toolbar);
+ setSupportActionBar(myChildToolbar);
+
+ // Get a support ActionBar corresponding to this toolbar
+ ActionBar ab = getSupportActionBar();
+
+ // Enable the Up button
+ ab.setDisplayHomeAsUpEnabled(true);
+}
+
+
++ You do not need to catch the up action in the activity's {@link + android.app.Activity#onOptionsItemSelected onOptionsItemSelected()} method. + Instead, that method should call its superclass, as shown in Respond to Actions. The superclass method + responds to the Up selection by navigating to the parent + activity, as specified in the app manifest. + diff --git a/docs/html/training/training_toc.cs b/docs/html/training/training_toc.cs index 296334520e500..002fb09927dde 100644 --- a/docs/html/training/training_toc.cs +++ b/docs/html/training/training_toc.cs @@ -1388,7 +1388,6 @@ results."
|