public PagerSlidingTabStrip(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { MyOnGlobalLayoutListner = new MyOnGlobalLayoutListener(this); adapterObserver = new PagerAdapterObserver(this); FillViewport = true; this.VerticalScrollBarEnabled = false; this.HorizontalScrollBarEnabled = false; SetWillNotDraw(false); tabsContainer = new LinearLayout(context); tabsContainer.Orientation = Android.Widget.Orientation.Horizontal; tabsContainer.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent); AddView(tabsContainer); var dm = Resources.DisplayMetrics; scrollOffset = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, scrollOffset, dm); indicatorHeight = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, indicatorHeight, dm); underlineHeight = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, underlineHeight, dm); dividerPadding = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, dividerPadding, dm); tabPadding = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, tabPadding, dm); dividerWidth = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, dividerWidth, dm); tabTextSize = (int)TypedValue.ApplyDimension(ComplexUnitType.Sp, tabTextSize, dm); //get system attrs (android:textSize and android:textColor) var a = context.ObtainStyledAttributes(attrs, Attrs); tabTextSize = a.GetDimensionPixelSize(TextSizeIndex, tabTextSize); var colorStateList = a.GetColorStateList(TextColorIndex); var textPrimaryColor = a.GetColor(TextColorPrimaryIndex, Android.Resource.Color.White); if (colorStateList != null) { tabTextColor = colorStateList; } else { tabTextColor = GetColorStateList(textPrimaryColor); } underlineColor = textPrimaryColor; dividerColor = textPrimaryColor; indicatorColor = textPrimaryColor; var paddingLeft = a.GetDimensionPixelSize(PaddingLeftIndex, padding); var paddingRight = a.GetDimensionPixelSize(PaddingRightIndex, padding); //In case we have the padding they must be equal so we take the biggest padding = Math.Max(paddingLeft, paddingRight); a = context.ObtainStyledAttributes(attrs, Resource.Styleable.PagerSlidingTabStrip); indicatorColor = a.GetColor(Resource.Styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor); underlineColor = a.GetColor(Resource.Styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor); dividerColor = a.GetColor(Resource.Styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor); dividerWidth = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_pstsDividerWidth, dividerWidth); indicatorHeight = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight); underlineHeight = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight); dividerPadding = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding); tabPadding = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding); tabBackgroundResId = a.GetResourceId(Resource.Styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId); shouldExpand = a.GetBoolean(Resource.Styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand); scrollOffset = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset); textAllCaps = a.GetBoolean(Resource.Styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps); isPaddingMiddle = a.GetBoolean(Resource.Styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle); tabTypefaceStyle = (TypefaceStyle)a.GetInt(Resource.Styleable.PagerSlidingTabStrip_pstsTextStyle, (int)TypefaceStyle.Bold); tabTypefaceSelectedStyle = (TypefaceStyle)a.GetInt(Resource.Styleable.PagerSlidingTabStrip_pstsTextSelectedStyle, (int)TypefaceStyle.Bold); tabTextAlpha = a.GetFloat(Resource.Styleable.PagerSlidingTabStrip_pstsTextAlpha, HalfTransparent); tabTextSelectedAlpha = a.GetFloat(Resource.Styleable.PagerSlidingTabStrip_pstsTextSelectedAlpha, Opaque); a.Recycle(); SetMarginBottomTabContainer(); rectPaint = new Paint(); rectPaint.AntiAlias = true; rectPaint.SetStyle(Paint.Style.Fill); dividerPaint = new Paint(); dividerPaint.AntiAlias = true; dividerPaint.StrokeWidth = dividerWidth; defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.MatchParent); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MatchParent, 1.0f); }
public PagerSlidingTabStrip (Context context, IAttributeSet attrs, int defStyle) : base (context, attrs, defStyle) { MyOnGlobalLayoutListner = new MyOnGlobalLayoutListener (this); adapterObserver = new PagerAdapterObserver (this); FillViewport = true; this.VerticalScrollBarEnabled = false; this.HorizontalScrollBarEnabled = false; SetWillNotDraw(false); tabsContainer = new LinearLayout (context); tabsContainer.Orientation = Android.Widget.Orientation.Horizontal; tabsContainer.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent); AddView(tabsContainer); var dm = Resources.DisplayMetrics; scrollOffset = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, scrollOffset, dm); indicatorHeight = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, indicatorHeight, dm); underlineHeight = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, underlineHeight, dm); dividerPadding = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, dividerPadding, dm); tabPadding = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, tabPadding, dm); dividerWidth = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, dividerWidth, dm); tabTextSize = (int)TypedValue.ApplyDimension(ComplexUnitType.Sp, tabTextSize, dm); //get system attrs (android:textSize and android:textColor) var a = context.ObtainStyledAttributes(attrs, Attrs); tabTextSize = a.GetDimensionPixelSize(TextSizeIndex, tabTextSize); var colorStateList = a.GetColorStateList(TextColorIndex); var textPrimaryColor = a.GetColor(TextColorPrimaryIndex, Android.Resource.Color.White); underlineColor = textPrimaryColor; dividerColor = textPrimaryColor; indicatorColor = textPrimaryColor; int padding = a.GetDimensionPixelSize(PaddingIndex, 0); paddingLeft = padding > 0 ? padding : a.GetDimensionPixelSize(PaddingLeftIndex, 0); paddingRight = padding > 0 ? padding : a.GetDimensionPixelSize(PaddingRightIndex, 0); a = context.ObtainStyledAttributes(attrs, Resource.Styleable.PagerSlidingTabStrip); indicatorColor = a.GetColor(Resource.Styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor); underlineColor = a.GetColor(Resource.Styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor); dividerColor = a.GetColor(Resource.Styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor); dividerWidth = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_pstsDividerWidth, dividerWidth); indicatorHeight = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight); underlineHeight = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight); dividerPadding = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding); tabPadding = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding); tabBackgroundResId = a.GetResourceId(Resource.Styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId); shouldExpand = a.GetBoolean(Resource.Styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand); scrollOffset = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset); textAllCaps = a.GetBoolean(Resource.Styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps); isPaddingMiddle = a.GetBoolean(Resource.Styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle); tabTypefaceStyle = (TypefaceStyle)a.GetInt(Resource.Styleable.PagerSlidingTabStrip_pstsTextStyle, (int)TypefaceStyle.Bold); tabTypefaceSelectedStyle = (TypefaceStyle)a.GetInt(Resource.Styleable.PagerSlidingTabStrip_pstsTextSelectedStyle, (int)TypefaceStyle.Bold); tabTextColorSelected = a.GetColorStateList(Resource.Styleable.PagerSlidingTabStrip_pstsTextColorSelected); textAlpha = a.GetInt(Resource.Styleable.PagerSlidingTabStrip_pstsTextAlpha, textAlpha); a.Recycle(); tabTextColor = colorStateList == null ? GetColorStateList(Color.Argb(textAlpha, Color.GetRedComponent(textPrimaryColor), Color.GetGreenComponent(textPrimaryColor), Color.GetBlueComponent(textPrimaryColor))) : colorStateList; tabTextColorSelected = tabTextColorSelected == null ? GetColorStateList(textPrimaryColor) : tabTextColorSelected; SetMarginBottomTabContainer(); rectPaint = new Paint(); rectPaint.AntiAlias = true; rectPaint.SetStyle(Paint.Style.Fill); dividerPaint = new Paint(); dividerPaint.AntiAlias = true; dividerPaint.StrokeWidth = dividerWidth; defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.MatchParent); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MatchParent, 1.0f); }