public PagerTabStrip(Context paramContext, AttributeSet paramAttributeSet) { super(paramContext, paramAttributeSet); mTabPaint.setColor(mIndicatorColor); float f = getResourcesgetDisplayMetricsdensity; mIndicatorHeight = ((int) (3.0F * f + 0.5F)); mMinPaddingBottom = ((int) (6.0F * f + 0.5F)); mMinTextSpacing = ((int) (64.0F * f)); mTabPadding = ((int) (16.0F * f + 0.5F)); mFullUnderlineHeight = ((int) (1.0F * f + 0.5F)); mMinStripHeight = ((int) (f * 32.0F + 0.5F)); mTouchSlop = ViewConfiguration.get(paramContext).getScaledTouchSlop(); setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), getPaddingBottom()); setTextSpacing(getTextSpacing()); setWillNotDraw(false); mPrevText.setFocusable(true); mPrevText.setOnClickListener( new View.OnClickListener() { public final void onClick(View paramAnonymousView) { mPager.setCurrentItem(mPager.getCurrentItem() - 1); } }); mNextText.setFocusable(true); mNextText.setOnClickListener( new View.OnClickListener() { public final void onClick(View paramAnonymousView) { mPager.setCurrentItem(mPager.getCurrentItem() + 1); } }); if (getBackground() == null) { mDrawFullUnderline = true; } }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); strip.setDrawFullUnderline(false); strip.setTabIndicatorColor(Color.DKGRAY); strip.setBackgroundColor(Color.GRAY); strip.setNonPrimaryAlpha(0.5f); strip.setTextSpacing(15); strip.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); // Note: 此处使用ViewPager,只能使用getChildFragmentManager(),否则弹栈将出现问题 // http://stackoverflow.com/questions/7338823/viewpager-recursive-entry-to-executependingtransactions viewPager.setAdapter(new HomePagerAdapter(getChildFragmentManager())); viewPager.setOnPageChangeListener(new HomePageChangeListener()); viewPager.setPageTransformer(false, new HomePageTransformer()); }
public PagerTabStrip(Context context, AttributeSet attrs) { super(context, attrs); mIndicatorColor = mTextColor; mTabPaint.setColor(mIndicatorColor); // Note: this follows the rules for Resources#getDimensionPixelOffset/Size: // sizes round up, offsets round down. final float density = context.getResources().getDisplayMetrics().density; mIndicatorHeight = (int) (INDICATOR_HEIGHT * density + 0.5f); mMinPaddingBottom = (int) (MIN_PADDING_BOTTOM * density + 0.5f); mMinTextSpacing = (int) (MIN_TEXT_SPACING * density); mTabPadding = (int) (TAB_PADDING * density + 0.5f); mFullUnderlineHeight = (int) (FULL_UNDERLINE_HEIGHT * density + 0.5f); mMinStripHeight = (int) (MIN_STRIP_HEIGHT * density + 0.5f); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); // Enforce restrictions setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), getPaddingBottom()); setTextSpacing(getTextSpacing()); setWillNotDraw(false); mPrevText.setFocusable(true); mPrevText.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { mPager.setCurrentItem(mPager.getCurrentItem() - 1); } }); mNextText.setFocusable(true); mNextText.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { mPager.setCurrentItem(mPager.getCurrentItem() + 1); } }); if (getBackground() == null) { mDrawFullUnderline = true; } }