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) has a new feature is self-identification, that is, to advertise themselves, so a lot of applications are 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.

At the time of using Actionbar. Will find a problem.

Actionbar is not supported in the 3.0 SDK, so it would be necessary to use an open source project Actionbarsherlock If the phone apk is compatible with a 2.2 or 2.3 phone, for example, the following:

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

2. Import into Eclipse (and import the project step again, check the is Library)


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


4. Change the subject to @style/theme.sherlock.light (or its sub-category)

5, Inherit sherlockactivity.

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

The above method will be able to achieve the low version number using Actionbar, but Goole launched its own compatibility package last year. More convenient to use.

Let's take a look at how to use the SUPPORT_V7.

1. Download and import the appcompat_7.x Compatibility Pack as above (assuming the official latest SDK development tools are available)

2. References in the project:


3. Change the subject to @style/theme.appcompat (or its sub-category)

4. Change the corresponding XML file under the menu/folder

<?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= "Many other" android:icon= "@drawable/ic_action_overflow" alpha:showasaction= "Always" > <menu > <group > <item android:id= "@+id/item                       1 " 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"/> &L   t;/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);

Perfect execution on Android 2.2 and 2.3 phones ...


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

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.