//private void UpdateTabHeader() {
        //    if (this.tabLayout.TabCount != this.Element.Children.Count)
        //        return;

        //    for (var i = 0; i < this.Element.Children.Count; i++) {
        //        var page = this.Element.Children[i];
        //        if (string.IsNullOrEmpty(page.Icon)) {
        //            var glyph = (string)page.GetValue(AttachedFontIcon.GlyphProperty);
        //            if (!string.IsNullOrWhiteSpace(glyph)) {
        //                var font = (string)page.GetValue(AttachedFontIcon.FontFamilyProperty);
        //                var size = (int)(double)page.GetValue(AttachedFontIcon.FontSizeProperty);

        //                var tab = this.tabLayout.GetTabAt(i);

        //                var ss = new SpannableString(glyph);
        //                var fontSpan = new CustomTypefaceSpan(font);
        //                ss.SetSpan(fontSpan, 0, 2, SpanTypes.ExclusiveExclusive);
        //                tab.SetText(ss);
        //            }
        //        }
        //    }
        //}


        private void UpdateTabIcons1() {
            var tabLayout = this.tabLayout;
            if (tabLayout.TabCount != this.Element.Children.Count)
                return;

            var builder = new TextDrawableBuilder(this.Context);
            //builder.SetColor(Color.Accent.ToAndroid());

            var arr = this.Context.ObtainStyledAttributes(new int[] { Resource.Attribute.colorPrimary });
            var color = arr.GetColor(0, 0);
            builder.SetColor(color);

            for (int i = 0; i < this.Element.Children.Count; ++i) {
                var page = this.Element.Children[i];
                if (string.IsNullOrEmpty(page.Icon)) {
                    var glyph = (string)page.GetValue(AttachedFontIcon.GlyphProperty);
                    if (!string.IsNullOrWhiteSpace(glyph)) {
                        builder.SetText(glyph);

                        var font = (string)page.GetValue(AttachedFontIcon.FontFamilyProperty);
                        if (!string.IsNullOrWhiteSpace(font))
                            builder.SetFont(font.ToTypeface());

                        var size = (int)(double)page.GetValue(AttachedFontIcon.FontSizeProperty);
                        builder.SetSize(size);

                        tabLayout.GetTabAt(i)
                            .SetIcon(builder.Build());
                    }
                }
            }
        }
Exemplo n.º 2
0
        //private void UpdateTabHeader() {
        //    if (this.tabLayout.TabCount != this.Element.Children.Count)
        //        return;

        //    for (var i = 0; i < this.Element.Children.Count; i++) {
        //        var page = this.Element.Children[i];
        //        if (string.IsNullOrEmpty(page.Icon)) {
        //            var glyph = (string)page.GetValue(AttachedFontIcon.GlyphProperty);
        //            if (!string.IsNullOrWhiteSpace(glyph)) {
        //                var font = (string)page.GetValue(AttachedFontIcon.FontFamilyProperty);
        //                var size = (int)(double)page.GetValue(AttachedFontIcon.FontSizeProperty);

        //                var tab = this.tabLayout.GetTabAt(i);

        //                var ss = new SpannableString(glyph);
        //                var fontSpan = new CustomTypefaceSpan(font);
        //                ss.SetSpan(fontSpan, 0, 2, SpanTypes.ExclusiveExclusive);
        //                tab.SetText(ss);
        //            }
        //        }
        //    }
        //}


        private void UpdateTabIcons1()
        {
            var tabLayout = this.tabLayout;

            if (tabLayout.TabCount != this.Element.Children.Count)
            {
                return;
            }

            var builder = new TextDrawableBuilder(this.Context);
            //builder.SetColor(Color.Accent.ToAndroid());

            var arr   = this.Context.ObtainStyledAttributes(new int[] { Resource.Attribute.colorPrimary });
            var color = arr.GetColor(0, 0);

            builder.SetColor(color);

            for (int i = 0; i < this.Element.Children.Count; ++i)
            {
                var page = this.Element.Children[i];
                if (string.IsNullOrEmpty(page.Icon))
                {
                    var glyph = (string)page.GetValue(AttachedFontIcon.GlyphProperty);
                    if (!string.IsNullOrWhiteSpace(glyph))
                    {
                        builder.SetText(glyph);

                        var font = (string)page.GetValue(AttachedFontIcon.FontFamilyProperty);
                        if (!string.IsNullOrWhiteSpace(font))
                        {
                            builder.SetFont(font.ToTypeface());
                        }

                        var size = (int)(double)page.GetValue(AttachedFontIcon.FontSizeProperty);
                        builder.SetSize(size);

                        tabLayout.GetTabAt(i)
                        .SetIcon(builder.Build());
                    }
                }
            }
        }