Android about the use of Actionsherlock

Source: Internet
Author: User

The last one weeks have been actionsherlock made very uncomfortable (light to the foot care shop went to three times-decompression), it should not be very difficult AH (Android has been basic), after all, programming (although I am engaged in. NET, Java and. NET have 90% similarity, although no use J Ava does a project, but it doesn't know anything about Java ... Also have a few years, can read some information and examples, self-feeling, simple to do a bit of a line, but to achieve the degree of the project, or complex point, to now have not been able to understand ~

It seems that, or in the official website of the system to read the information from the beginning. Recently want to write their own Android APP, if not actionsherlock, looks like the beginning of a low point ah, hehe ~

The Actionbarsherlock, which is glued to the theme of the official compatibility library, is designed to allow users to use the design of the action Bar, which is an experience accumulated in the Android Ice Cream Sandwich. Before that, the design of the top action bar is still troublesome, usually consists of four parts, as shown in 1, from left to right, respectively, the application icon, view Control, Operation button and more operations, all need to do their own, and each developer on the action bar design may be different, actionbarsherlock It is precisely to simplify and standardize the design and implementation of the Operation Bar.

Figure 1 Android Action Bar Design

Android Ice Cream Sandwich is the next version of Android following Froyo. Because the Android version of the chaos has plagued Android developers, Ice Cream Sandwich solve two problems: fragmentation (Fragment) design, you can let the application on a small screen with a single panel layout, on the large screen with multiple panel layout To help developers navigate different sizes of screens.

View Google's design guidelines for the action bar.

What is Actionsherlock? In fact, Actionsherlock based on the previous design and practice of the Operation Bar, on the basis of native Android, a library of encapsulation, in order to facilitate identification and use, it in the package name, and its internal large number of classes in the name and location of the original Android match.

Requirements

Because Actionsherlock uses the native action bar and its associated classes for the Ice Cream Sandwich, the library requires that you compile Actionsherlock and your project using Android 4.0 or later. In addition, JDK 1.6 is also required.

Because the Actionsherlock library is an extension of the official library, you must refer to Android-support-v4.jarin your project.

How to include in your project

If you use the ADT plug-in version 0.9.7 or a higher Eclipse development environment, you can introduce actionbarsherlock into your project.

Create a new Android project in Eclipse using the Actionbarsherlock/folder as the existing source. Then, in your project properties, add the created project under the ' Libraries ' section of the ' Android ' category.

Other options include using ant to compile from the command line, and using Maven or Gradle to build your Android project, see "Actionbarsherlock official website".

Action Bar API

When creating an activity that uses the action bar in all Android versions, you must declare that your activity inherits any class that begins with "Sherlock" (for example,sherlockactivity, Sherlockfragmentactivity). Interaction with the action Bar is done by calling Getsupportactionbar ()(instead of Getactionbar ()).

The API exposed by the ActionBar instance is a full copy of the native method (native methods). In the "Related Links" section, refer to its documentation and how to use it.

Note: When using sherlockfragmentactivity , you also use the fragment class that starts with the "sherlock-" prefix to ensure the correct functionality (for example, Sherlockfragment, sherlocklistfragment). The activity is still the same as the normal fragment class function, but you will not be able to use any of the menu-related methods.

The necessary thematic

Because the action bar part is very complex, it requires a set of default themes. The library provides three core themes-either of which must be applied to every activity that you need to have the action bar present.

Please refer to "theming" for more information.

Reference

In order to use the function of the action bar, it must be in Android 3.0 + version, the library contains and uses a large number of classes, corresponding to the original Android package name. The most common are:

    • Com.actionbarsherlock.app.ActionBar
    • Com.actionbarsherlock.view.Menu
    • Com.actionbarsherlock.view.MenuItem
    • Com.actionbarsherlock.view.MenuInflater

For example, Com.actionbarsherlock.app.ActionBar corresponds to Com.android.app.ActionBar.

Adding these packages ensures that you use these types appropriately, as well as additional features.

Note: Most errors @Override methods from the activity are the result of incorrect import. All of the classes in the com.actionbarsherlock.* package, their names and locations match the native class.

Note: In order to inflate your menu from an XML file, you should call the Getsupportmenuinflater () method in your activitie. The fragment callback prepares an instance of the Inflater as a parameter. Recently I made this mistake, Eclipse reported a inflateexception, see this sentence I just understand.

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.