PagerSlidingTabStrip, pagerslidingtabstrip

Source: Internet
Author: User

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!

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.