PagerSlidingTabStrip, pagerslidingtabstrip
This article introduces PagerSlidingTabStrip ).
/*** PagerSlidingTabStrip test **/public class MainActivity extends FragmentActivity {private Fragment1 mFragment1; private Fragment2 mFragment2;/*** worker instance */private javastabs; /*** get the density of the current screen */private DisplayMetrics dm; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity _ Main); setOverflowShowingAlways (); dm = getResources (). getDisplayMetrics (); ViewPager pager = (ViewPager) findViewById (R. id. pager); tabs = (PagerSlidingTabStrip) findViewById (R. id. tabs); pager. setAdapter (new MyPagerAdapter (getSupportFragmentManager (); tabs. setViewPager (pager); setTabsValue ();}/*** assigns values to attributes of PagerSlidingTabStrip. */Private void setTabsValue () {// set the Tab to automatically fill the tabs with the full screen. setShouldExpand (true); // you can specify whether the Tab line is transparent. // tabs. setDividerColor (Color. TRANSPARENT); // set the height of the line at the bottom of the Tab. setUnderlineHeight (int) TypedValue. applyDimension (TypedValue. COMPLEX_UNIT_DIP, 3, dm); // sets the height of the Tab Indicator tabs. setIndicatorHeight (int) TypedValue. applyDimension (TypedValue. COMPLEX_UNIT_DIP, 2, dm); // set the text size of the Tab title tabs. setTextSize (( Int) TypedValue. applyDimension (TypedValue. COMPLEX_UNIT_SP, 16, dm); // sets the color of Tab Indicator tabs. setIndicatorColor (Color. parseColor ("# 45c01a"); // sets the color of the Selected Tab text (this is a custom method) tabs. setSelectedTextColor (Color. parseColor ("# 45c01a"); // deselect the background color tabs when you click Tab. setTabBackground (0);} public class MyPagerAdapter extends FragmentPagerAdapter {public MyPagerAdapter (FragmentManager fm) {super (fm);} private f Inal String [] titles = {"Apps", "MyData"}; @ Override public CharSequence getPageTitle (int position) {return titles [position];} @ Override public int getCount () {return titles. length ;}@ Override public Fragment getItem (int position) {switch (position) {case 0: if (mFragment1 = null) {mFragment1 = new Fragment1 ();} return mFragment1; case 1: if (mFragment2 = null) {mFragment2 = new Fragme Nt2 () ;}return mFragment2; default: return null ;}}@ Override public boolean onCreateOptionsMenu (Menu menu) {getMenuInflater (). inflate (R. menu. main, menu); return true ;}@ Override public boolean onMenuOpened (int featureId, Menu menu) {if (featureId = Window. FEATURE_ACTION_BAR & menu! = Null) {if (menu. getClass (). getSimpleName (). equals ("MenuBuilder") {try {Method m = menu. getClass (). getDeclaredMethod ("setOptionalIconsVisible", Boolean. TYPE); m. setAccessible (true); m. invoke (menu, true);} catch (Exception e) {}} return super. onMenuOpened (featureId, menu);} private void setOverflowShowingAlways () {try {ViewConfiguration config = ViewConfiguration. get (this); Field menuKeyField = ViewConfiguration. class. getDeclaredField ("sHasPermanentMenuKey"); menuKeyField. setAccessible (true); menuKeyField. setBoolean (config, false);} catch (Exception e) {e. printStackTrace ();}}}
2). Fragment: 3 .:
Http://download.csdn.net/detail/liranke/8758765
The power of open source is endless!