Use of actionbarsherlock -- (1) Configuration

Source: Internet
Author: User

Introduction:

Since Android 3.0, Android has added a new API named actoinbar. With the release and gradual promotion of Android 4.0, many applications have begun to use Google-promoted uidesign, actionbar is a very important part. I am a little bored with the design of iOS, And I am interested in the design style of Android 4.0. However, for program compatibility, we need to consider the problem of lower versions, therefore, the compatible package must be used here.

Google has not released the actionbar compatibility package for versions earlier than 3.0. Fortunately, the Internet provides open-source development by others, actionbarshelock, hereinafter referred to as abs.

ABS allows the 2. x system to use actionbar as well. ABS also provides many other functions provided after 3.0, such as fragement. Here we will only introduce the use of actionbar.

Another advantage of ABS is that if you use it on more than 3.0 machines, it will call the system's native actionbar. In addition, its usage method is quite similar to the system's own method. If you are familiar with actionbar itself, ABS can also get started quickly.


Download:

Download the program can go to the official website: http://actionbarsherlock.com/download.html on Windows to download the. Zip package can be, as of my post, ABS version is 4.3.1.

There is also a "usage" link on the official website. Due to the constant updates of the software, the tutorials are definitely beyond the reach of each other. Therefore, you should refer to the instructions on the official website for specific use.


Reference:

1. After downloading the. ZIP file, extract the actionbarsherlock folder to a location on the hard disk.

2. Open eclipse, select file -- New -- project -- Android project from existing code..., select the folder to be imported, and finish.

3. Right-click the imported project (actionbarsherlock should be called), select the bottom item, properties, and find "android" in the displayed dialog box to confirm that "is library" is selected. In this way, this project can be used as a library for reference by our project.

4. Open the attributes of a personal project (actionbar in this example), add the library in Android, click Add, and add the library we just imported, A green check mark indicates that the operation is successfully added.

5. After the import is successful, errors usually occur. The error is caused by repeated references to the android-support-v4.jar.

Because this package is referenced in ABS, and this package exists in our project, the two packages are different in general, so an error occurs. You only need to replace the two packages with the same one.

For example, copy the android-support-v4.jar in the libs folder of ABS to the lower part of the libs folder of our project and overwrite it.

Usage:

After the import is successful, we will add actionbarsherlock to our program.

1. In the androidmanifest. xml file of the program, modify the topic:

android:theme="@style/Theme.Sherlock.Light"

2. Open the program file, such as mainactivity. java. Reference:

import com.actionbarsherlock.app.ActionBar;import com.actionbarsherlock.app.ActionBar.OnNavigationListener;import com.actionbarsherlock.app.SherlockActivity;import com.actionbarsherlock.view.Menu;import com.actionbarsherlock.view.MenuInflater;import com.actionbarsherlock.view.MenuItem;

Note: not all of the above references will be used.

3. If you want the actionbar to display some menu buttons, you need to override oncreateoptionsmenu in the activity and rewrite onoptionsitemselected to respond to the clicking of these buttons. In addition, this activity must inherit the shelockactivity.

public class MainActivity extends SherlockActivity {                  @Override        public void onCreate(Bundle savedInstanceState) {            super.onCreate(savedInstanceState);            setContentView(R.layout.activity_main);                          }                      @Override        public boolean onOptionsItemSelected(MenuItem item) {            switch(item.getItemId()){            case R.id.menu_delete:                Toast.makeText(this, "delete", Toast.LENGTH_SHORT).show();                break;                      }            return super.onOptionsItemSelected(item);        }                      @Override        public boolean onCreateOptionsMenu(Menu menu) {            getSupportMenuInflater().inflate(R.menu.activity_main, menu);            return super.onCreateOptionsMenu(menu);        }                  }

R. Menu. activity_main is the layout file of the menu. The content is as follows:

<Menu xmlns: Android = "http://schemas.android.com/apk/res/android"> <item Android: Id = "@ + ID/Add" Android: icon = "@ Android: drawable/ic_menu_add" Android: showasaction = "ifroom" Android: Title = "add" Android: titlecondensed = "add"> </item> </menu>

After running, effects (Virtual Machine version, API-8 2.2)

This article is written here first. I hope you can give some advice to this article.

Reprinted please indicate from: http://blog.csdn.net/icyfox_bupt/article/details/9286387

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.