Android official Getting Started document [5] Create action Bar

Source: Internet
Author: User

Android official Getting Started document [5] Create action Bar Setting up the action Bar
Create Action Bar

This lesson teaches
1.Support Android 3.0 and Above only
2.Support Android 2.1 and Above

You should also read
? Setting up the support Library

This lesson teaches you
1. Only support Android3.0 and above
2. Support Android2.1 and above

You should also read
? set up support libraries

In its more basic form, the Action bar displays the title for the activity and the app icon on the left. Even in this simple form, the action Bar was useful for all activities to inform users on the where they are and to maintain A consistent identity for your app.
In its most basic form, the action bar displays the activity and title of the application icon on the left. Even in this simple form, the action bar is very useful for all activities to tell users where they are and keep your application consistent.

Figure 1. An action bar with the app icon and activity title.
Figure 1. The application icon and the action bar of the caption activity.

Setting up a basic action bar requires this your app use an activity theme that enables the action bar. How to request such a theme depends on which version of Android are the lowest supported by your app. So this lesson was divided into the sections depending on which Android version is your lowest supported.
Creating a basic action bar requires your application to use the active theme to make the action bar. How to apply for such a subject depends on which version of Android is the lowest supported for your application. So, this course is divided into two parts, depending on the minimum support for Android version.

Support for Android 3.0 and Above only
Support for Android3.0 and above only

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

Beginning with Android 3.0 (API level One), the action Bar is included in all activities so use the Theme.holo Theme (or One of its descendants), which are the default theme when either the Targetsdkversion or Minsdkversion attribute are set to "One" or greater.
Starting with Android 3.0 (API level 11), the action Bar is included in all use Theme.holo themes (or its subclasses), which is the default theme when either Targetsdkversion or the Minsdkversion property is set to "11" or greater.


The action bar to your activities, simply set either attribute to one or higher. For example:
So in the action Bar add to your activity, just set any property to 11 or higher. For example:

<manifest ... >
<USES-SDK android:minsdkversion= "one" .../>
...
</manifest>

Note:if you ' ve created a custom theme, being sure it uses one of the Theme.holo themes as its parent. For details, see styling the Action Bar.
Note: If you have already created a custom theme, be sure that it takes one of the Theme.holo themes as its parent class. For more information, see the Action Bar for styles.

Now the Theme.holo Theme are applied to your apps and all activities show the action Bar. That ' s it.
Now the Theme.holo theme is applied to all activities in your app display action Bar. That's it.

Support for Android 2.1 and Above
Support Android2.1 and above


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

Adding the action Bar when running on versions older than Android 3.0 (off to Android 2.1) requires so you include the Android support Library in your application.
When running on older than Android3.0 (down to Android2.1) versions, the action bar takes you in your app, including the Android support library.


To get started, read the support Library Setup document and set up the V7 AppCompat Library (Once you ' ve downloaded the Li Brary package, follow the instructions for Adding libraries with resources).

Once you has the support Library integrated with your app project:
To get started, read the support library installation file and set up the V7 AppCompat library (once you download the library package, follow the instructions to add the library's resources).

Once your support library is integrated into your application's project:

1.Update your activity so it extends actionbaractivity. For example:

1. Update your activity so that it expands actionbaractivity. For example:

public class Mainactivity extends Actionbaractivity {...}


2.In your manifest file, update either the <application> element or individual <activity> elements to use one of the Theme.appcompat themes. For Example:2. In your manifest file, update either the <application> element or one of the Theme.appcompat themes used by the personal < active > element. For example

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

Note:if you ' ve created a custom theme, being sure it uses one of the Theme.appcompat themes as its parent. For details, see styling the Action Bar.
Note: If you have already created a custom theme, be sure that it takes one of the Theme.appcompat themes as its parent class. For more information, see the Action Bar for styles.

Now your activity includes the action Bar is running on Android 2.1 (API level 7) or higher.
Your activity now includes the action Bar when running at Android2.1 (API7 level) or later.

Remember to properly set your app's API level support in the manifest:
Remember to correctly set the API level support manifest checklist for your application:

<manifest ... >
<USES-SDK android:minsdkversion= "7" android:targetsdkversion= "/>"
...
</manifest>

This article is translated from: https://developer.android.com/training/basics/actionbar/setting-up.html

Android official Getting Started document [5] Create 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.