コード例 #1
0
        public virtual void SetAppearance(UITabBarController controller, ShellAppearance appearance)
        {
            IShellAppearanceElement appearanceElement = appearance;
            var backgroundColor = appearanceElement.EffectiveTabBarBackgroundColor;
            var foregroundColor = appearanceElement.EffectiveTabBarForegroundColor;         // currently unused
            var disabledColor   = appearanceElement.EffectiveTabBarDisabledColor;           // unused on iOS
            var unselectedColor = appearanceElement.EffectiveTabBarUnselectedColor;
            var titleColor      = appearanceElement.EffectiveTabBarTitleColor;

            var tabBar = controller.TabBar;

            if (_defaultTint == null)
            {
                _defaultBarTint        = tabBar.BarTintColor;
                _defaultTint           = tabBar.TintColor;
                _defaultUnselectedTint = tabBar.UnselectedItemTintColor;
            }

            if (!backgroundColor.IsDefault)
            {
                tabBar.BarTintColor = backgroundColor.ToUIColor();
            }
            if (!titleColor.IsDefault)
            {
                tabBar.TintColor = titleColor.ToUIColor();
            }
            if (!unselectedColor.IsDefault)
            {
                tabBar.UnselectedItemTintColor = unselectedColor.ToUIColor();
            }
        }
        public virtual void SetAppearance(BottomNavigationView bottomView, ShellAppearance appearance)
        {
            IShellAppearanceElement controller = appearance;
            var background = controller.EffectiveTabBarBackgroundColor;
            var foreground = controller.EffectiveTabBarForegroundColor;
            var disabled   = controller.EffectiveTabBarDisabledColor;
            var unselected = controller.EffectiveTabBarUnselectedColor;
            var title      = controller.EffectiveTabBarTitleColor;


            if (_defaultList == null)
            {
#if __ANDROID_28__
                _defaultList = bottomView.ItemTextColor ?? MakeColorStateList(title.ToAndroid().ToArgb(), disabled.ToAndroid().ToArgb(), unselected.ToAndroid().ToArgb());
#else
                _defaultList = bottomView.ItemTextColor;
#endif
            }

            var colorStateList = MakeColorStateList(title, disabled, unselected);
            bottomView.ItemTextColor    = colorStateList;
            bottomView.ItemIconTintList = colorStateList;

            colorStateList.Dispose();

            SetBackgroundColor(bottomView, background);
        }
コード例 #3
0
        public void SetAppearance(UITabBarController controller, ShellAppearance appearance)
        {
            IShellAppearanceElement appearanceElement = appearance;
            var backgroundColor = appearanceElement.EffectiveTabBarBackgroundColor;
            var unselectedColor = appearanceElement.EffectiveTabBarUnselectedColor;
            var titleColor      = appearanceElement.EffectiveTabBarTitleColor;

            var  tabBar = controller.TabBar;
            bool operatingSystemHasUnselectedTint = UIDevice.CurrentDevice.CheckSystemVersion(10, 0);

            if (_defaultTint == null)
            {
                _defaultBarTint = tabBar.BarTintColor;
                _defaultTint    = tabBar.TintColor;
                if (operatingSystemHasUnselectedTint)
                {
                    _defaultUnselectedTint = tabBar.UnselectedItemTintColor;
                }
            }

            if (!backgroundColor.IsDefault)
            {
                tabBar.BarTintColor = backgroundColor.ToUIColor();
            }

            if (!titleColor.IsDefault)
            {
                tabBar.TintColor = titleColor.ToUIColor();
            }

            if (operatingSystemHasUnselectedTint && !unselectedColor.IsDefault)
            {
                tabBar.UnselectedItemTintColor = unselectedColor.ToUIColor();
            }
        }
コード例 #4
0
        public virtual void SetAppearance(UITabBarController controller, ShellAppearance appearance)
        {
            IShellAppearanceElement appearanceElement = appearance;
            var backgroundColor = appearanceElement.EffectiveTabBarBackgroundColor;
            var foregroundColor = appearanceElement.EffectiveTabBarForegroundColor;         // Currently unused
            var disabledColor   = appearanceElement.EffectiveTabBarDisabledColor;           // Unused on iOS
            var unselectedColor = appearanceElement.EffectiveTabBarUnselectedColor;
            var titleColor      = appearanceElement.EffectiveTabBarTitleColor;

            var  tabBar = controller.TabBar;
            bool operatingSystemSupportsUnselectedTint = Forms.IsiOS10OrNewer;

            if (_defaultTint == null)
            {
                _defaultBarTint = tabBar.BarTintColor;
                _defaultTint    = tabBar.TintColor;

                if (operatingSystemSupportsUnselectedTint)
                {
                    _defaultUnselectedTint = tabBar.UnselectedItemTintColor;
                }
            }

            if (Forms.IsiOS15OrNewer)
            {
                UpdateiOS15TabBarAppearance(controller, appearance);
            }
            else
            {
                UpdateTabBarAppearance(controller, appearance);
            }
        }
コード例 #5
0
        void UpdateTabBarAppearance(UITabBarController controller, ShellAppearance appearance)
        {
            IShellAppearanceElement appearanceElement = appearance;
            var backgroundColor = appearanceElement.EffectiveTabBarBackgroundColor;
            var unselectedColor = appearanceElement.EffectiveTabBarUnselectedColor;
            var titleColor      = appearanceElement.EffectiveTabBarTitleColor;

            var tabBar = controller.TabBar;

            if (backgroundColor != null)
            {
                tabBar.BarTintColor = backgroundColor.ToUIColor();
            }
            if (titleColor.IsDefault != null)
            {
                tabBar.TintColor = titleColor.ToUIColor();
            }

            bool operatingSystemSupportsUnselectedTint = Forms.IsiOS10OrNewer;

            if (operatingSystemSupportsUnselectedTint)
            {
                if (unselectedColor.IsDefault != null)
                {
                    tabBar.UnselectedItemTintColor = unselectedColor.ToUIColor();
                }
            }
        }
コード例 #6
0
        public virtual void SetAppearance(UITabBarController controller, ShellAppearance appearance)
        {
            IShellAppearanceElement appearanceElement = appearance;
            var backgroundColor = appearanceElement.EffectiveTabBarBackgroundColor;
            var foregroundColor = appearanceElement.EffectiveTabBarForegroundColor;         // Currently unused
            var disabledColor   = appearanceElement.EffectiveTabBarDisabledColor;           // Unused on iOS
            var unselectedColor = appearanceElement.EffectiveTabBarUnselectedColor;
            var titleColor      = appearanceElement.EffectiveTabBarTitleColor;

            var tabBar = controller.TabBar;

            if (_defaultTint == null)
            {
                _defaultBarTint        = tabBar.BarTintColor;
                _defaultTint           = tabBar.TintColor;
                _defaultUnselectedTint = tabBar.UnselectedItemTintColor;
            }

            if (PlatformVersion.IsAtLeast(15))
            {
                UpdateiOS15TabBarAppearance(controller, appearance);
            }
            else
            {
                UpdateTabBarAppearance(controller, appearance);
            }
        }
コード例 #7
0
        public virtual void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
        {
            IShellAppearanceElement controller = appearance;
            var backgroundColor = controller.EffectiveTabBarBackgroundColor;
            var foregroundColor = controller.EffectiveTabBarForegroundColor;             // currently unused
            var disabledColor   = controller.EffectiveTabBarDisabledColor;
            var unselectedColor = controller.EffectiveTabBarUnselectedColor;
            var titleColor      = controller.EffectiveTabBarTitleColor;

            if (_defaultList == null)
            {
#if __ANDROID_28__
                _defaultList = bottomView.ItemTextColor ?? bottomView.ItemIconTintList
                               ?? MakeColorStateList(titleColor.ToAndroid().ToArgb(), disabledColor.ToAndroid().ToArgb(), unselectedColor.ToAndroid().ToArgb());
#else
                _defaultList = bottomView.ItemTextColor ?? bottomView.ItemIconTintList;
#endif
            }

            _colorStateList             = MakeColorStateList(titleColor, disabledColor, unselectedColor);
            bottomView.ItemTextColor    = _colorStateList;
            bottomView.ItemIconTintList = _colorStateList;

            SetBackgroundColor(bottomView, backgroundColor);
        }
コード例 #8
0
        //public void SetAppearance(BottomNavigationView bottomView, ShellAppearance appearance)
        //{
        //    // Hide title for bottom nav items
        //    // https://montemagno.com/xamarin-forms-fully-customize-bottom-tabs-on-android-turn-off-shifting/
        //    bottomView.LabelVisibilityMode = LabelVisibilityMode.LabelVisibilityLabeled;


        //    IMenu myMenu = bottomView.Menu;

        //    IMenuItem myItemOne = myMenu.GetItem(0);

        //    //if (myItemOne.IsChecked)
        //    //{
        //    //    myItemOne.SetIcon(Resource.Drawable.icon_home);
        //    //}
        //    //else
        //    //{
        //    //    myItemOne.SetIcon(Resource.Drawable.icon_home);
        //    //}

        //    //The same logic if you have myItemTwo, myItemThree....

        //}

        public void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
        {
            bottomView.LabelVisibilityMode = LabelVisibilityMode.LabelVisibilityLabeled;


            IMenu myMenu = bottomView.Menu;

            IMenuItem myItemOne = myMenu.GetItem(0);
        }
コード例 #9
0
        public virtual void SetAppearance(BottomNavigationView bottomView, ShellAppearance appearance)
        {
            IShellAppearanceElement controller = appearance;
            var backgroundColor = controller.EffectiveTabBarBackgroundColor;
            var foregroundColor = controller.EffectiveTabBarForegroundColor;             // currently unused
            var disabledColor   = controller.EffectiveTabBarDisabledColor;
            var unselectedColor = controller.EffectiveTabBarUnselectedColor;
            var titleColor      = controller.EffectiveTabBarTitleColor;


            if (_defaultList == null)
            {
コード例 #10
0
        void UpdateiOS15TabBarAppearance(UITabBarController controller, ShellAppearance appearance)
        {
            IShellAppearanceElement appearanceElement = appearance;

            controller.TabBar
            .UpdateiOS15TabBarAppearance(
                ref _tabBarAppearance,
                null,
                null,
                appearanceElement.EffectiveTabBarForegroundColor,
                appearanceElement.EffectiveTabBarUnselectedColor,
                appearanceElement.EffectiveTabBarBackgroundColor,
                appearanceElement.EffectiveTabBarTitleColor);
        }
コード例 #11
0
        public void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
        {
            IMenu myMenu = bottomView.Menu;

            for (int i = 0; i < myMenu.Size(); i++)
            {
                var             item = myMenu.GetItem(i);
                SpannableString span = new SpannableString(item.ToString());
                int             end  = span.Length();
                //span.SetSpan(new AbsoluteSizeSpan(14, true), 0, end, SpanTypes.ExclusiveExclusive);
                span.SetSpan(new Rel ativeSizeSpan(0.8f), 0, end, SpanTypes.ExclusiveExclusive);
                item.SetTitle(span);
            }
        }
        public void SetAppearance(UITabBarController controller, ShellAppearance appearance)
        {
            IShellAppearanceElement el = appearance;
            var backgroundColor        = el.EffectiveTabBarBackgroundColor;
            var foregroundColor        = el.EffectiveTabBarForegroundColor;
            var titleColor             = el.EffectiveTabBarTitleColor;
            var disabledColor          = el.EffectiveTabBarDisabledColor;
            var unselectedColor        = el.EffectiveTabBarUnselectedColor;

            var tabBar = controller.TabBar;

            if (_blurView == null)
            {
                _defaultBackgroundImage = tabBar.BackgroundImage;
                _defaultTint            = tabBar.TintColor;
                _defaultUnselectedTint  = tabBar.UnselectedItemTintColor;

                var effect = UIBlurEffect.FromStyle(UIBlurEffectStyle.Regular);
                _blurView       = new UIVisualEffectView(effect);
                _blurView.Frame = tabBar.Bounds;

                _colorView = new UIView(_blurView.Frame);
            }

            tabBar.BackgroundImage = new UIImage();

            tabBar.InsertSubview(_colorView, 0);
            tabBar.InsertSubview(_blurView, 0);

            var button = new UIButton(UIButtonType.Custom);

            button.SetTitle("test", UIControlState.Normal);
            button.Frame  = tabBar.Bounds;
            button.Center = tabBar.Center;
            tabBar.InsertSubview(button, 1);

            if (!backgroundColor.IsDefault)
            {
                _colorView.BackgroundColor = backgroundColor.ToUIColor();
            }
            if (!foregroundColor.IsDefault)
            {
                tabBar.TintColor = foregroundColor.ToUIColor();
            }
            if (!unselectedColor.IsDefault)
            {
                tabBar.UnselectedItemTintColor = unselectedColor.ToUIColor();
            }
        }
コード例 #13
0
        public virtual void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
        {
            IShellAppearanceElement controller = appearance;
            var backgroundColor = controller.EffectiveTabBarBackgroundColor;
            var foregroundColor = controller.EffectiveTabBarForegroundColor;             // currently unused
            var disabledColor   = controller.EffectiveTabBarDisabledColor;
            var unselectedColor = controller.EffectiveTabBarUnselectedColor;
            var titleColor      = controller.EffectiveTabBarTitleColor;

            _colorStateList             = MakeColorStateList(titleColor, disabledColor, unselectedColor);
            bottomView.ItemTextColor    = _colorStateList;
            bottomView.ItemIconTintList = _colorStateList;

            SetBackgroundColor(bottomView, backgroundColor);
        }
コード例 #14
0
        public override void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
        {
            base.SetAppearance(bottomView, appearance);

            var menu = bottomView.Menu;

            for (int i = 0; i < bottomView.Menu.Size(); i++)
            {
                var      menuItem = menu.GetItem(i);
                var      title    = menuItem.TitleFormatted;
                Typeface typeface = Typeface.CreateFromAsset(MainActivity.Instance.Assets, "Chocolate Covered Raindrops.ttf");
                var      sb       = new SpannableStringBuilder(title);

                sb.SetSpan(new CustomTypefaceSpan("", typeface), 0, sb.Length(), SpanTypes.InclusiveInclusive);
                menuItem.SetTitle(sb);
            }
        }
コード例 #15
0
        void UpdateTabBarAppearance(UITabBarController controller, ShellAppearance appearance)
        {
            IShellAppearanceElement appearanceElement = appearance;
            var backgroundColor = appearanceElement.EffectiveTabBarBackgroundColor;
            var unselectedColor = appearanceElement.EffectiveTabBarUnselectedColor;
            var titleColor      = appearanceElement.EffectiveTabBarTitleColor;

            var tabBar = controller.TabBar;

            if (backgroundColor != null)
            {
                tabBar.BarTintColor = backgroundColor.ToPlatform();
            }
            if (titleColor.IsDefault != null)
            {
                tabBar.TintColor = titleColor.ToPlatform();
            }
            if (unselectedColor.IsDefault != null)
            {
                tabBar.UnselectedItemTintColor = unselectedColor.ToPlatform();
            }
        }
コード例 #16
0
        public override void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
        {
            base.SetAppearance(bottomView, appearance);

            if (Build.VERSION.SdkInt < BuildVersionCodes.P)
            {
                return;
            }

            TypefaceSpan typefaceSpan = new TypefaceSpan(CustomShellRenderer.BottomTabTitleTypeface);

            for (int i = 0; i < bottomView.Menu.Size(); i++)
            {
                var menuItem = bottomView.Menu.GetItem(i);
                if (menuItem.TitleFormatted == null)
                {
                    return;
                }
                SpannableStringBuilder spannableTitle = new SpannableStringBuilder(menuItem.TitleFormatted);
                spannableTitle.SetSpan(typefaceSpan, 0, spannableTitle.Length(), 0);
                menuItem.SetTitle(spannableTitle);
            }
        }
コード例 #17
0
        public void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
        {
            _shellAppearance = appearance;
            IMenu menu = bottomView.Menu;

            for (int i = 0; i < menu.Size(); i++)
            {
                IMenuItem menuItem = menu.GetItem(i);

                var      title            = menuItem.TitleFormatted;
                Typeface typeface         = Typeface.CreateFromAsset(_context.AndroidContext.Assets, "Ubuntu-Regular.ttf");
                SpannableStringBuilder sb = new SpannableStringBuilder(title);

                sb.SetSpan(new CustomTypefaceSpan("", typeface), 0, sb.Length(), SpanTypes.InclusiveInclusive);
                //sb.SetSpan(new ForegroundColorSpan(_shellAppearance.EffectiveTabBarForegroundColor.ToAndroid()), 0, sb.Length(), SpanTypes.InclusiveInclusive);
                //sb.SetSpan(new ForegroundColorSpan(_shellAppearance.EffectiveTabBarForegroundColor.ToAndroid()), 0, sb.Length(), SpanTypes.InclusiveInclusive);

                menuItem.SetTitle(sb);
                //_context.AndroidContext
            }

            SetBottomViewColours(bottomView);
        }
コード例 #18
0
        public override void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
        {
            base.SetAppearance(bottomView, appearance);
            IMenu menu  = bottomView.Menu;
            var   items = new List <IMenuItem>();
            int   index = 0;

            do
            {
                try
                {
                    items.Add(menu.GetItem(index++));
                }
                catch
                {
                    break;
                }
            } while (true);

            foreach (var item in items)
            {
                // TODO: Add gradient support
            }
        }
コード例 #19
0
 public void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
 {
     //throw new System.NotImplementedException();
 }
コード例 #20
0
 public void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
 {
     bottomView.SetBackgroundColor(Android.Graphics.Color.White);
     bottomView.LabelVisibilityMode = LabelVisibilityMode.LabelVisibilityUnlabeled;
 }
コード例 #21
0
 public override void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
 {
     base.SetAppearance(bottomView, appearance);
     bottomView.LabelVisibilityMode = LabelVisibilityMode.LabelVisibilityUnlabeled;
 }
コード例 #22
0
        void UpdateiOS15TabBarAppearance(UITabBarController controller, ShellAppearance appearance)
        {
            IShellAppearanceElement appearanceElement = appearance;

            var tabBar = controller.TabBar;

            var tabBarAppearance = new UITabBarAppearance();

            tabBarAppearance.ConfigureWithOpaqueBackground();

            // Set TabBarBackgroundColor
            var tabBarBackgroundColor = appearanceElement.EffectiveTabBarBackgroundColor;

            if (tabBarBackgroundColor != null)
            {
                tabBarAppearance.BackgroundColor = tabBarBackgroundColor.ToPlatform();
            }

            // Set TabBarTitleColor
            var tabBarTitleColor = appearanceElement.EffectiveTabBarTitleColor;

            // Update colors for all variations of the appearance to also make it work for iPads, etc. which use different layouts for the tabbar
            // Also, set ParagraphStyle explicitly. This seems to be an iOS bug. If we don't do this, tab titles will be truncat...
            if (tabBarTitleColor != null)
            {
                tabBarAppearance.StackedLayoutAppearance.Normal.TitleTextAttributes = tabBarAppearance.StackedLayoutAppearance.Selected.TitleTextAttributes = new UIStringAttributes {
                    ForegroundColor = tabBarTitleColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default
                };
                tabBarAppearance.StackedLayoutAppearance.Normal.IconColor = tabBarAppearance.StackedLayoutAppearance.Selected.IconColor = tabBarTitleColor.ToPlatform();

                tabBarAppearance.InlineLayoutAppearance.Normal.TitleTextAttributes = tabBarAppearance.InlineLayoutAppearance.Selected.TitleTextAttributes = new UIStringAttributes {
                    ForegroundColor = tabBarTitleColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default
                };
                tabBarAppearance.InlineLayoutAppearance.Normal.IconColor = tabBarAppearance.InlineLayoutAppearance.Selected.IconColor = tabBarTitleColor.ToPlatform();

                tabBarAppearance.CompactInlineLayoutAppearance.Normal.TitleTextAttributes = tabBarAppearance.CompactInlineLayoutAppearance.Selected.TitleTextAttributes = new UIStringAttributes {
                    ForegroundColor = tabBarTitleColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default
                };
                tabBarAppearance.CompactInlineLayoutAppearance.Normal.IconColor = tabBarAppearance.CompactInlineLayoutAppearance.Selected.IconColor = tabBarTitleColor.ToPlatform();
            }

            //Set TabBarUnselectedColor
            var tabBarUnselectedColor = appearanceElement.EffectiveTabBarUnselectedColor;

            if (tabBarUnselectedColor != null)
            {
                tabBarAppearance.StackedLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes {
                    ForegroundColor = tabBarUnselectedColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default
                };
                tabBarAppearance.StackedLayoutAppearance.Normal.IconColor = tabBarUnselectedColor.ToPlatform();

                tabBarAppearance.InlineLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes {
                    ForegroundColor = tabBarUnselectedColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default
                };
                tabBarAppearance.InlineLayoutAppearance.Normal.IconColor = tabBarUnselectedColor.ToPlatform();

                tabBarAppearance.CompactInlineLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes {
                    ForegroundColor = tabBarUnselectedColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default
                };
                tabBarAppearance.CompactInlineLayoutAppearance.Normal.IconColor = tabBarUnselectedColor.ToPlatform();
            }

            // Set TabBarDisabledColor
            var tabBarDisabledColor = appearanceElement.EffectiveTabBarDisabledColor;

            if (tabBarDisabledColor != null)
            {
                tabBarAppearance.StackedLayoutAppearance.Disabled.TitleTextAttributes = new UIStringAttributes {
                    ForegroundColor = tabBarDisabledColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default
                };
                tabBarAppearance.StackedLayoutAppearance.Disabled.IconColor = tabBarDisabledColor.ToPlatform();

                tabBarAppearance.InlineLayoutAppearance.Disabled.TitleTextAttributes = new UIStringAttributes {
                    ForegroundColor = tabBarDisabledColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default
                };
                tabBarAppearance.InlineLayoutAppearance.Disabled.IconColor = tabBarDisabledColor.ToPlatform();

                tabBarAppearance.CompactInlineLayoutAppearance.Disabled.TitleTextAttributes = new UIStringAttributes {
                    ForegroundColor = tabBarDisabledColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default
                };
                tabBarAppearance.CompactInlineLayoutAppearance.Disabled.IconColor = tabBarDisabledColor.ToPlatform();
            }

            tabBar.StandardAppearance = tabBar.ScrollEdgeAppearance = tabBarAppearance;
        }