I have done the following:
Create an entry in attrs.xml like this
<resources> <declare-styleable name="SegmentedTabLayout"> <attr name="fontSize" format="dimension" /> </declare-styleable> </resources>
Then create a font size property and initialize the method that you will call in the constructor as follows
public float FontSize { get; set; } private void InitializeAttrs(Context context, IAttributeSet attrs) { if (context == null || attrs == null) return; var styleAttributes = context.ObtainStyledAttributes(attrs, Resource.Styleable.SegmentedTabLayout); if (styleAttributes == null) return; FontSize = styleAttributes.GetDimension(Resource.Styleable.SegmentedTabLayout_fontSize, -1); styleAttributes.Recycle(); }
Then I used the viral 9966 method (improved it a bit) and called it in the NewTab override method as follows
public override Tab NewTab() { var tab = base.NewTab(); ChangeFontSize(tab); return tab; } private void ChangeFontSize(Tab tab) { if (FontSize < 0) return; var tabViewGroup = (ViewGroup)tab.View; for (int i = 0; i < tabViewGroup.ChildCount; i++) { if (tabViewGroup.GetChildAt(i) is TextView textView) { textView.TextSize = FontSize; } } }
And this is it :)
Jop Middelkamp May 14 '19 at 5:53 a.m. 2019-05-14 05:53
source share