Android Chinese Translator-Adding the action Bar to add activity bars (action Bar)

Source: Internet
Author: User

2014-10-28 Yunfei Zhang Vir translated from: https://developer.android.com/training/basics/actionbar/index.html

Add Activity Bar (Adding the action Bar)

Translator Note: I can not find a better vocabulary translation action Bar, although I also think the activity bar is not a good translation, but always have a Chinese name. However, in order to facilitate identification, this article continues to use the English Actionbar

Activity Bar Action Bar is one of the most important design elements that you can implement for your activity in your app. It provides a number of user interface features that make your app instantly feel affinity to users, and it provides consistency in different Android apps. Key features include:

    • Provide a dedicated area for your app to identify, and indicate the user's current location in the app.
    • Access important activities in a predictable way (e.g. search)
    • Supports navigation and view switching (implemented via tabs or drop-down lists)

This training session provides a quick guide to the basics of Action Bar. For more information about the various features of Actionbar, see the Action Bar Guide.

Course

Set the Action Bar

Learn how to add a base action bar to your activity, whether your app only supports Android 3.0 and above or also supports the same version as Android 2.1 (by using the Android Support Library of the Android™ libraries)

Add Active button

Learn how to add on action Bar and respond to user activity.

Style your Action Bar

Learn how to customize the appearance of your action bar

Override Action Bar

Learn how to override the action bar before your layout, allowing you to seamlessly convert when you hide the action bar.

------------------------------------------------

2014-10-28 Yunfei Zhang translated from: https://developer.android.com/training/basics/actionbar/setting-up.html

set the action bar

In most of its basic forms, Action bar displays a caption for activity and then an app icon on the left. Even in this simple form, action Bar is still useful for all activity, informing the user where they are and maintaining a consistent identity for the app.

Table 1. A simple action bar with an app icon and activity title.

Setting up a basic action bar requires that your app use a theme with the action Bar enabled. How to request a topic like this depends on the minimum supported version of your app. Then this class is divided into two chapters according to your minimum supported Android version.

Only Android 3.0 or above is supported

From Android 3.0 (API level), Action Bar is included in all activity that uses the Theme.holo theme (or one of its descendant successors), and it will be the targetSdkVersion minSdkVersion 属性被设置为 "11" default style when or even larger.

Then, to add the action Bar to your activity, it's easy to set this property to 11 or higher. such as the following:

<manifest >    <uses-sdk android:minsdkversion= "one     " .../> ... </manifest>

Note: If you create a custom theme, make sure it uses a Theme.holo theme as its parent topic. For more details, please read styling the Action Bar.

Now the Theme.holo theme is applied to your app, and all activity shows the action bar. That's it.

Support Android 2.1 or above

When running in earlier versions of Biandro 3.0 (down to the 2.1 version), to add the action bar, you need to include the Android support library in your application.

At the beginning, read the Support library setup document and set up the v7 AppCompat Library (once you have downloaded the library's package, follow the instructions for using the Resource Add library Adding libraries with resources).

Once you have integrated the Android support library in your app project.

1. Update your activity to inherit it from ActionBarActivity . For example:

 Public class extends actionbaractivity {...}

2. In your manifest file manifest, update the <application> elements or separate <activity> elements using a Theme.AppCompat theme, such as:

<activity android:theme= "@style/theme.appcompat.light" ... >

Note: If you create a custom theme, make sure it uses a Theme.holo theme as its parent topic. For more details, please read styling the Action Bar.

Now your activity contains actionbar when it runs on Android 2.1 (API level 7) or higher.

Remember, in the manifest file manifest, set the API levels that your app supports, as appropriate:

<manifest >    <uses-sdk android:minsdkversion= "7"  android:targetsdkversion= "/>     " ... </manifest>

Next lesson: Add an action button. Next:adding ACTION BUTTONS

----------------------------------------------------------

2014-10-29 Yunfei Zhang translated from: https://developer.android.com/training/basics/actionbar/adding-buttons.html

Add action button (Adding action Buttons)

The action Bar allows you to add buttons for those active items (action items) that are associated to the current context of the app. The action buttons known to you are those that display an icon and/or text activity directly in the action bar, those that cannot be filled in actionbar or are not important enough to be hidden in the overflow portion of the action

(Translator Note: We can see the icon or text is the button action buttons, invisible is hidden extension button action overflow)

Figure I. An action bar contains an action button and an action overflow part for searching, which shows the extended button.

Specifying an activity in XML (specify the actions in XML)

All action buttons and other items available in the Extended button (action overflow) are defined in an XML menu resource, menu resource. To add an action to the Action Bar, res/menu/ create an XML file under the folder of your project.

For each item that you want to include in the action, add the <item> element, for example:

Res/menu/main_activity_actions.xml

<menu xmlns:android= "Http://schemas.android.com/apk/res/android" >    <!--Search, should appear as action Button--    <item android:id= "@+id/action_search"          android:icon= "@drawable/ic_action_search "          android:title=" @string/action_search "          android:showasaction=" Ifroom "/>    <! --Settings, should always is in the overflow and    <item android:id= "@+id/action_settings"          android: Title= "@string/action_settings"          android:showasaction= "Never"/></menu>

Not to be continued ...

Android Chinese Translator-Adding the action Bar to add activity bars (action Bar)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.