Android Rookie's growth note (--google) official Actionbar support for Andoird 2.x

Source: Internet
Author: User

In Google's official Android Design Guide (link: http://www.apkbus.com/design/get-started/ ui-overview.html) There is a new feature is self-identification, that is, to promote themselves, so many applications now also natural use of actionbar and provide their own logo.

Application of:


This is what Google's Android design guide says: The app's launch icon is the best place to showcase your logo as an entry point for launching your app. You can also place the launch icon on the action Bar to ensure that it is visible on all pages within the app.

When you use Actionbar, you will find a problem. Actionbar is not supported in the SDK before 3.0, so if the phone apk to be compatible with 2.2 or 2.3 mobile phone needs to use an open source project Actionbarsherlock, the use of the following methods:

1. Download Open Source package: http://actionbarsherlock.com/usage.html

2. Import into Eclipse (same as Import project step, check is Library)


3, reference in the project (properties->android->add add in)


4. Modify the theme to @style/theme.sherlock.light (or its subclasses)

5, Inherit sherlockactivity.

6. Use Getsupportactionbar () to get the Actionbar object.

The above method can realize the problem of low version using Actionbar, but Goole introduced its own Compatibility pack last year, which is more convenient to use. Let's take a look at how to use SUPPORT_V7.

1. Download and import the appcompat_7.x Compatibility Pack as above (provided if it is the official latest SDK development tool)

2. References in the project:


3. Modify the theme to @style/theme.appcompat (or its subclasses)

4. Modify the corresponding XML file in the menu/directory

<?xml version= "1.0" encoding= "Utf-8"?> <menu xmlns:android= "Http://schemas.android.com/apk/res/android" XM        Lns:alpha= "Http://schemas.android.com/apk/res-auto" > <!--Search, should appear as action button--- <item android:id= "@+id/action_search" android:icon= "@drawable/ic_action_refresh" Android:tit      Le= "Refresh" alpha:showasaction= "Always"/> <!--Settings, should always is in the overflow- <item android:id= "@+id/action_add" android:title= "Share" android:icon= "@drawable/ic_action_shar E "alpha:showasaction=" Always "/> <item android:id=" @+id/action_settings "Androi             d:title= "More" android:icon= "@drawable/ic_action_overflow" alpha:showasaction= "Always" >                         <menu > <group > <item android:id= "@+id/item1" Android:title= "Personal Center" android:icon= "@drawable/ic_action_share"/> <item Android:id= "@+id/item2" android:title= "Settings" android:icon= "                        @drawable/ic_action_share "/> <item android:id=" @+id/exit_system " Android:title= "Exit" android:icon= "@drawable/ic_action_share"/> <   /group> </menu> </item> </menu>
5. Inherit from actionbaractivity

6. Use Getsupportactionbar to get Actionbar objects.

ActionBar ActionBar = Getsupportactionbar (); actionbar.setdisplayshowhomeenabled (true); Actionbar.seticon ( R.drawable.actionbar_icon);

Run flawlessly on Android 2.2 and 2.3 phones ...


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.