Next blog: http://blog.csdn.net/geniuseoe2012/article/details/8982469
It mentioned that GitHub-client uses many open source third-party libraries.
The first one is actionbarsherklock. As we all know, actionbar has been provided since android3.0, which makes the android user experience much better, but this actionbar is not supported below android3.0, google has not released any solutions, but nothing can be done. on GitHub, some cool people released the open-source actionbarsherlock to implement actionbar on android2.x, if you use android on your mobile phone, it will call the native actionbar. The following is a simple example of how to use it in combination with the actual use case.
First download the source code from the https://github.com/JakeWharton/ActionBarSherlock to get the Directory
Actionbarsherlock is used as a link project to be referenced by other projects.
Actionbarsherlock-samples is a sample project, which is actually a demo of Some APIs.
This is very important. Take a closer look at the shoes and run the examples all over the code. You will be able to master how to use them.
However, the demo uses the actionbarsherklock native style or the built-in style.
Our projects often have their own styles, which requires us to transform the style and set theme.
For details, refer to the example project style. The effect is as follows:
This article is based on the actionbar application of Netease news client.
First, the original version
Instructor lan's cottage Edition
Code snippet:
Public class slidertabpageractivity extends implements limit, tablistener {private int COUNT = 0; private list <datastruct> MList; private viewpager mviewpager; private layoutinflater minflater; @ define void oncreate (bundle arg0) {super. oncreate (arg0); setcontentview (R. layout. slider_tab_pager_layout); setupviews (); initdata () ;}@ overrideprotected void ondestroy () {// todo auto-generated method stubsuper. ondestroy () ;}@ overridepublic Boolean oncreateoptionsmenu (menu) {getsupportmenuinflater (). inflate (R. menu. main_menu, menu); Return true;} @ override public Boolean onoptionsitemselected (menuitem item) {Switch (item. getitemid () {Case android. r. id. home: Toast. maketext (this, "home", toast. length_short ). show (); Return true; case R. id. menu_setting: Toast. maketext (this, "setting", toast. length_short ). show (); Return true; default: return Super. onoptionsitemselected (item) ;}} private void setupviews () {minflater = getlayoutinflater (); mviewpager = (viewpager) findviewbyid (R. id. PAGER); mviewpager. setonpagechangelistener (this); actionbar = getsupportactionbar (); actionbar. setnavigationmode (actionbar. navigation_mode_tabs); string [] arrstrings = getresources (). getstringarray (R. array. sections); Count = arrstrings. length; For (INT I = 0; I <count; I ++) {tab = actionbar. newtab (); tab. setcustomview (gettabview (arrstrings [I]); tab. settablistener (this); actionbar. addtab (Tab);} actionbar. setdisplayhomeasupenabled (true); actionbar. setlogo (R. drawable. biz_pics_main_back_normal); actionbar. settitle ("Netease image");} private void initdata () {MList = new arraylist <datastruct> (); For (INT I = 0; I <count; I ++) {datastruct struct = new datastruct (); struct. index = I; struct. dastring = "tab -->" + I; MList. add (struct);} mviewpager. setadapter (New sliderpageradapter (getsuppfrfragmentmanager (), MList);} private view gettabview (String title) {view = minflater. inflate (R. layout. tab_item_layout, null); textview = (textview) view. findviewbyid (R. id. textview); textview. settext (title); Return view;} @ overridepublic void onpagescrollstatechanged (INT arg0) {// todo auto-generated method stub} @ overridepublic void onpagescrolled (INT arg0, float arg1, int arg2) {// todo auto-generated method stub} @ overridepublic void onpageselected (INT position) {getsupportactionbar (). setselectednavigationitem (position) ;}@ overridepublic void ontabselected (Tab tab, fragmenttransaction ft) {mviewpager. setcurrentitem (tab. getposition () ;}@ overridepublic void ontabunselected (Tab tab, fragmenttransaction ft) {// todo auto-generated method stub} @ overridepublic void ontabreselected (Tab tab, fragmenttransaction ft) {// todo auto-generated method stub} class sliderpageradapter extends fragmentstatepageradapter {private list <datastruct> MList; Public sliderpageradapter (fragmentmanager FM, list <datastruct> List) {super (FM ); MList = List ;}@ overridepublic fragment getitem (int pos) {return New sliderfragment (MList. get (POS) ;}@ overridepublic int getcount () {return MList. size () ;}} public static class sliderfragment extends sherlockfragment {private datastruct mstruct; Public sliderfragment (datastruct struct) {mstruct = struct ;}@ overridepublic void oncreate (bundle detail. oncreate (savedinstancestate) ;}@ overridepublic view oncreateview (layoutinflater Inflater, viewgroup container, bundle savedinstancestate) {view = Inflater. inflate (R. layout. layout1, null); textview tview = (textview) view. findviewbyid (R. id. textview); tview. settext (mstruct. tostring (); Return view ;}}}
Sytle Configuration
<style name="Themes.Sliders.Actionbar" parent="@style/Theme.Sherlock.Light"> <item name="actionBarStyle">@style/Widget.Slider.ActionBar</item> <item name="actionBarTabStyle">@style/Widget.Slider.ActionBarTab</item> <item name="actionBarItemBackground">@drawable/selector_actionbar_button</item> <item name="homeAsUpIndicator">@drawable/biz_widget_left</item> <item name="android:actionBarStyle">@style/Widget.Slider.ActionBar</item> <item name="android:actionBarTabStyle">@style/Widget.Slider.ActionBarTab</item> <item name="android:actionBarItemBackground">@drawable/selector_actionbar_button</item> <item name="android:homeAsUpIndicator">@drawable/biz_widget_left</item> </style> <style name="Widget.Slider.ActionBar" parent="@style/Widget.Sherlock.ActionBar"> <item name="android:background">@drawable/base_actionbar_bg</item> <item name="android:backgroundStacked">#ffeeeeee</item> <item name="android:titleTextStyle">@style/TextAppearance.Slider.Widget.ActionBar.Titlen</item> <item name="titleTextStyle">@style/TextAppearance.Slider.Widget.ActionBar.Titlen</item> <item name="background">@drawable/base_actionbar_bg</item> <item name="backgroundStacked">#ffeeeeee</item> </style> <style name="Widget.Slider.ActionBarTab" parent="@style/Widget.Sherlock.ActionBar.TabView"> <item name="android:background">@drawable/tab_indicator</item> </style> <style name="Widget.Slider.ActionButton" parent="@style/Widget.Sherlock.ActionButton"> <item name="android:background">@drawable/selector_actionbar_button</item> <item name="background">@drawable/selector_actionbar_button</item> </style> <style name="TextAppearance.Slider.Widget.ActionBar.Titlen" parent="@style/TextAppearance.Sherlock.Widget.ActionBar.Title"> <item name="android:textColor">#eeeeee</item> <item name="android:textSize">20sp</item> </style>
Let's take down the project and compare it carefully to find out which fields correspond to which UI Effects
For more details, refer to the style file in the actionbarsherklock project.
The custom style inherits the native style and then modifies the corresponding field.
You should note that the style fields contain Android prefix and fields without Android prefix, as shown in figure
<style name="Widget.Slider.ActionBar" parent="@style/Widget.Sherlock.ActionBar"> <item name="android:background">@drawable/base_actionbar_bg</item> <item name="android:backgroundStacked">#ffeeeeee</item> <item name="android:titleTextStyle">@style/TextAppearance.Slider.Widget.ActionBar.Titlen</item> <item name="titleTextStyle">@style/TextAppearance.Slider.Widget.ActionBar.Titlen</item> <item name="background">@drawable/base_actionbar_bg</item> <item name="backgroundStacked">#ffeeeeee</item> </style>
This is because 2. when using its sytle in X, the field item without the android prefix is used. If it is more than 3.0, the native field is used. Therefore, both fields must be set, otherwise, it may take effect in different system versions.
Link to the project:
Http://download.csdn.net/detail/geniuseoe2012/5535041
I want to know what to do later and listen to the next Decomposition
More brilliant, please pay attention to my csdn blog --> http://blog.csdn.net/geniuseoe2012