コード例 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_main);

            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            indicator       = new DrawerArrowDrawable(this);
            indicator.Color = Color.White;
            SupportActionBar.SetHomeAsUpIndicator(indicator);

            SetTransformer();
            // setListener();
            drawerLayout = FindViewById <DrawerLayout>(Resource.Id.drawerLayout);
            drawerLayout.SetScrimColor(Color.Transparent);
            drawerLayout.AddDrawerListener(this);
        }
コード例 #2
0
        void UpdateToolbar()
        {
            if (_disposed)
            {
                return;
            }

            Context  context             = Context;
            AToolbar bar                 = _toolbar;
            ActionBarDrawerToggle toggle = _drawerToggle;

            if (bar == null)
            {
                return;
            }

            bool isNavigated = NavigationPageController.StackDepth > 1;

            bar.NavigationIcon = null;
            Page currentPage = Element.CurrentPage;

            if (isNavigated)
            {
                if (NavigationPage.GetHasBackButton(currentPage))
                {
                    if (toggle != null)
                    {
                        toggle.DrawerIndicatorEnabled = false;
                        toggle.SyncState();
                    }

                    var icon = new DrawerArrowDrawable(context.GetThemedContext());
                    icon.Progress      = 1;
                    bar.NavigationIcon = icon;

                    var prevPage        = Element.Peek(1);
                    var backButtonTitle = NavigationPage.GetBackButtonTitle(prevPage);
                    _defaultNavigationContentDescription = backButtonTitle != null
                                                ? bar.SetNavigationContentDescription(prevPage, backButtonTitle)
                                                : bar.SetNavigationContentDescription(prevPage, _defaultNavigationContentDescription);
                }
                else if (toggle != null && _flyoutPage != null)
                {
                    toggle.DrawerIndicatorEnabled = _flyoutPage.ShouldShowToolbarButton();
                    toggle.SyncState();
                }
            }
            else
            {
                if (toggle != null && _flyoutPage != null)
                {
                    toggle.DrawerIndicatorEnabled = _flyoutPage.ShouldShowToolbarButton();
                    toggle.SyncState();
                }
            }

            Color tintColor = Element.BarBackgroundColor;

            if (tintColor == null)
            {
                bar.BackgroundTintMode = null;
            }
            else
            {
                bar.BackgroundTintMode = PorterDuff.Mode.Src;
                bar.BackgroundTintList = ColorStateList.ValueOf(tintColor.ToAndroid());
            }

            Brush barBackground = Element.BarBackground;

            bar.UpdateBackground(barBackground);

            Color textColor = Element.BarTextColor;

            if (textColor != null)
            {
                bar.SetTitleTextColor(textColor.ToAndroid().ToArgb());
            }

            Color navIconColor = NavigationPage.GetIconColor(Current);

            if (navIconColor != null && bar.NavigationIcon != null)
            {
                bar.NavigationIcon.SetColorFilter(navIconColor, FilterMode.SrcAtop);
            }

            bar.Title = currentPage?.Title ?? string.Empty;

            if (_toolbar.NavigationIcon != null && textColor != null)
            {
                var icon = _toolbar.NavigationIcon as DrawerArrowDrawable;
                if (icon != null)
                {
                    icon.Color = textColor.ToAndroid().ToArgb();
                }
            }

            UpdateTitleIcon();

            UpdateTitleView();
        }
コード例 #3
0
        void UpdateToolbar()
        {
            if (_disposed)
            {
                return;
            }

            Context  context             = Context;
            var      activity            = (FormsAppCompatActivity)context;
            AToolbar bar                 = _toolbar;
            ActionBarDrawerToggle toggle = _drawerToggle;

            if (bar == null)
            {
                return;
            }

            bool isNavigated = NavigationPageController.StackDepth > 1;

            bar.NavigationIcon = null;
            Page currentPage = Element.CurrentPage;

            if (isNavigated)
            {
                if (toggle != null)
                {
                    toggle.DrawerIndicatorEnabled = false;
                    toggle.SyncState();
                }

                if (NavigationPage.GetHasBackButton(currentPage))
                {
                    var icon = new DrawerArrowDrawable(activity.SupportActionBar.ThemedContext);
                    icon.Progress      = 1;
                    bar.NavigationIcon = icon;

                    var prevPage = Element.Peek(1);
                    _defaultNavigationContentDescription = bar.SetNavigationContentDescription(prevPage, _defaultNavigationContentDescription);
                }
            }
            else
            {
                if (toggle != null && _masterDetailPage != null)
                {
                    toggle.DrawerIndicatorEnabled = _masterDetailPage.ShouldShowToolbarButton();
                    toggle.SyncState();
                }
            }

            Color tintColor = Element.BarBackgroundColor;

            if (Forms.IsLollipopOrNewer)
            {
                if (tintColor.IsDefault)
                {
                    bar.BackgroundTintMode = null;
                }
                else
                {
                    bar.BackgroundTintMode = PorterDuff.Mode.Src;
                    bar.BackgroundTintList = ColorStateList.ValueOf(tintColor.ToAndroid());
                }
            }
            else
            {
                if (tintColor.IsDefault && _backgroundDrawable != null)
                {
                    bar.SetBackground(_backgroundDrawable);
                }
                else if (!tintColor.IsDefault)
                {
                    if (_backgroundDrawable == null)
                    {
                        _backgroundDrawable = bar.Background;
                    }
                    bar.SetBackgroundColor(tintColor.ToAndroid());
                }
            }

            Color textColor = Element.BarTextColor;

            if (!textColor.IsDefault)
            {
                bar.SetTitleTextColor(textColor.ToAndroid().ToArgb());
            }

            bar.Title = currentPage.Title ?? "";

            UpdateTitleIcon();

            UpdateTitleView();
        }
コード例 #4
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            var drawer    = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            var imageView = FindViewById <ImageView>(Resource.Id.drawer_indicator);

            _drawerArrowDrawable = new DrawerArrowDrawable(Resources)
            {
                StrokeColor = Resources.GetColor(Resource.Color.light_gray)
            };
            imageView.SetImageDrawable(_drawerArrowDrawable);

            drawer.DrawerSlide += (sender, args) =>
            {
                _offset = args.SlideOffset;

                if (_offset >= .995)
                {
                    _flipped = true;
                    _drawerArrowDrawable.Flip = _flipped;
                }
                else if (_offset <= .005)
                {
                    _flipped = false;
                    _drawerArrowDrawable.Flip = _flipped;
                }

                _drawerArrowDrawable.Parameter = _offset;
            };

            imageView.Click += (sender, args) =>
            {
                if (drawer.IsDrawerVisible((int)GravityFlags.Start))
                {
                    drawer.CloseDrawer((int)GravityFlags.Start);
                }
                else
                {
                    drawer.OpenDrawer((int)GravityFlags.Start);
                }
            };

            var styleButton = FindViewById <TextView>(Resource.Id.indicator_style);
            var rounded     = false;

            styleButton.Click += (sender, args) =>
            {
                styleButton.Text = rounded ? "See Rounded" : "See Squared";
                rounded          = !rounded;

                _drawerArrowDrawable = new DrawerArrowDrawable(Resources, rounded)
                {
                    Parameter   = _offset,
                    Flip        = _flipped,
                    StrokeColor = Resources.GetColor(Resource.Color.light_gray)
                };

                imageView.SetImageDrawable(_drawerArrowDrawable);
            };
        }