1. Example description
- Since Android 3.0, Android has introduced actoinbar. It must be said that before Android 3.0, the title bar of Android is really ugly and there is no function yet.
- In the past, the top columns of many applications were similar to Apple, for example. With the release and gradual expansion of Android 4.0 and Android 4.2, many applications have begun to use the uidesign promoted by Google, and actionbar is a very important part.
- Google has not released the actionbar compatibility package for versions earlier than 3.0. Fortunately, the Internet provides open-source development by others, actionbarshelock, or ABS for short.
- 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.
- Http://actionbarsherlock.com/download the corresponding compressed package
2. Running result
3. CoreCode
@ Overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); getsuppactionactionbar (). setdisplayhomeasupenabled (true);} @ overridepublic Boolean oncreateoptionsmenu (COM. actionbarsherlock. view. menu) {getsupportmenuinflater (). inflate (R. menu. main, menu); return Super. oncreateoptionsmenu (menu);} @ overridepublic Boolean onoptionsitemselected (Menuitem item) {Switch (item. getitemid () {case R. Id. menu_settings: Toast. maketext (this, "actionbarsherlock settings! ", Toast. length_long). Show (); break; case R. Id. homeasup: Toast. maketext (this," Home! ", Toast. length_long). Show (); break;} return Super. onoptionsitemselected (item );}
4. Precautions
1. Your project buildtarget must be in the range of 4.0 + and API 14 +. Otherwise, the theme. holo XML file cannot read resources, and the r file cannot be generated.
2. Because actionbarsherlock contains the android_support_v4 package, you do not need to import another package. If you have previously imported the package, you must delete it. Otherwise, a conflict may occur.
3. Sometimes you will be promptedProgramIt is not a library error. You only need to check the islibrary in Properties> android in actionbarsherlock.
4. To use actionbar to inherit from sherlockactivity, you must add theme settings when declaring activity in the configuration file, and there are only three types of theme and three types of parents.
5. Watch the video to explain
Http://www.eyeandroid.com/thread-11914-1-1.html