In the most current form of action Bar, it only shows the activity's title and the app's icon on the left. Even in this simple form, it just tells the user which activity is now in the app and keeps an identity for your app.
Figure 1. An action bar showing the app icon and activity title
Setting a basic action bar requires that your app use a theme that supports action bar. How to request such a subject depends on the minimum supported Android version of your app you choose. So this lesson will be divided into two sections based on the different Android minimum versions supported by your app.
Supports Android version 3.0 and above
Starting with Android 3.0 (API level 11), all activity uses the Theme.Holo theme (or its subtopics), including the action Bar, targetSdkVersion when your or minSdkVersion property is set to 11 or higher, The Theme.holo theme is to apply the default theme.
So to add an action bar for your activity, simply make it one of the above properties is 11 or higher. As shown below:
<manifest ... > <USES-SDK android:minsdkversion="One" ... /> ...</manifest>
Tip: If you create a custom theme, make sure it is a Theme.Holo sub-topic of the theme. For more information, please see styling the Action Bar.
So now that your app is using the Theme.Holo theme, you'll see action bar in all your activity.
Supports Android 2.1 and later (less than Android 3.0)
To add an action bar to an app running on Android 3.0 (as low as 2.1) versions of your device, you need to import the Android support Library into your app.
As a start, read the support library Setup document and add the v7 AppCompat Library (when you are finished downloading the support package, import it according to the adding Libraries with resources documentation).
Once your application project integrates the support Library:
- Let your activity inherit.
ActionBarActivity。 For example:
Public class mainactivity extends actionbaractivity { ... }
- In your manifest file, in your
<application>Element or a separate<activity>element is used in theTheme.AppCompatTheme. For example:
<activity android:theme = "@style/ Theme.AppCompat.Light " >
Tip: If you create a custom theme and make sure it's a Theme.AppCompat sub-topic, read styling the Action Bar for details.
Now your activity in Android 2.1 (API level 7) or later is included with Action Bar.
Remember to get the amount of settings your app supports for Android API versions:
<manifest ... > <USES-SDK android:minsdkversion="7" android:targetsdkversion=" " /> ...</manifest>
Translator note: For apps created with the latest version of ADT, ADT automatically imports the support package if the app is set to a minimum of Android version 2.2 or higher (less than 3.0) ( v7 AppCompat library ). Reference: http://blog.csdn.net/sweetvvck/article/details/38345671,http://blog.csdn.net/sweetvvck/article/details/ 38346547