Combination of ActionBarSherlock Tab and ViewPager

Source: Internet
Author: User

Recently, I encountered a problem in a small project, that is, using TabWidget and ViewPager to create a Tab That Can Be slide. The effect can still be displayed on Android2.3, but the TabWeight style will be changed to the holo style on the 4.0 system. If text and icons are added to Tabweight. In the 4.0 system, only text is displayed by default (an icon is displayed when the text is empty ).

I cannot accept the two display effects of the same application.

Then I searched the internet.

Find a solution: http://stackoverflow.com/questions/10745092/icon-in-tab-is-not-showing-up

However, I think custom TabWeight will make a simple problem more complicated.

The original intention is to create a TAB interface that can be slide, so that tabhost, ViewPager, and custom TabWeight are used, and the structure is too cumbersome. It is better to simplify the problem.

Determine the style as holo. To be compatible with versions earlier than 4.0, use the ActionBarSherlock package

ActionBarSherlock can go to the http://actionbarsherlock.com/download.html under the website

You can also go to GIT to find the https://github.com/JakeWharton/ActionBarSherlock

Using the tab in ActionBarSherlock, the holo style is relatively simple, so no icon or anything is added to the flexibility.

I don't need to post my own code. I found an example on the Internet and pasted the key code. If you are interested, I 'd like to go to the original post and check it in detail.

 

 

  MyFragmentPagerAdapter   PAGE_COUNT = 2     Fragment getItem(=              0= "current_page", arg0+1             1= "current_page", arg0+1  

 

 

The code of the main MainActivity, and then the FragmentActivity in it can be added with either of them.
  MainActivity  ====   onPageSelected(= =    ="Android"="Apple"  

 

 

 

Example of the link http://wptrafficanalyzer.in/blog/implement-swiping-between-tabs-with-viewpager-in-action-bar-using-sherlock-library/ interested in students to see it

Related Article

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.