/// <summary>
        /// Gets the toolbar item drawable.
        /// </summary>
        /// <param name="toolbarItem">The toolbar item.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private static Drawable GetToolbarItemDrawable(this ToolbarItem toolbarItem, Context context)
        {
            if (String.IsNullOrWhiteSpace(toolbarItem.Icon))
            {
                return(null);
            }

            var iconItem = toolbarItem as IconToolbarItem;

            if (iconItem == null)
            {
                return(context.Resources.GetDrawable(toolbarItem.Icon));
            }

            var drawable = new IconDrawable(context, iconItem.Icon);

            if (drawable == null)
            {
                return(null);
            }

            if (iconItem.IconColor != Color.Default)
            {
                drawable = drawable.Color(iconItem.IconColor.ToAndroid());
            }

            return(drawable.ActionBarSize());
        }
Пример #2
0
        private static Drawable GetToolbarItemDrawable(this ToolbarItem toolbarItem, Context context)
        {
            if (String.IsNullOrWhiteSpace(toolbarItem.Icon))
            {
                return(null);
            }

            if (!(toolbarItem is IconToolbarItem iconItem))
            {
                return(context.GetDrawable(toolbarItem.Icon.File));
            }

            var drawable = new IconDrawable(context, iconItem.Icon.File, iconItem.FontFamily);

            if (iconItem.IconColor != Color.Default)
            {
                drawable = drawable.Color(iconItem.IconColor.ToAndroid());
            }

            return(drawable.ActionBarSize());
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            /* Needs to be registered only on the MainLauncher */
            Iconize.With(new MaterialModule());

            SetSupportActionBar(_toolbar);
            SupportActionBar.SetHomeButtonEnabled(true);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);

            /*
             * See Material Font Cheetsheat Here: https://goo.gl/FMCiR9
             */
            var icon = new IconDrawable(this, "md-menu");

            icon.Color(Color.White);

            /* Sets the size to the action bar, ready to put it there */
            icon.ActionBarSize();

            /* Add the icon the the ActionBar */
            SupportActionBar.SetHomeAsUpIndicator(icon);

            /* Implement the Hamburger Menu Selection Changed */
            _navigationView.NavigationItemSelected += (sender, item) =>
            {
                // Open Fragments Here
                Android.Support.V4.App.Fragment selectedFragment;
                switch (item.MenuItem.ItemId)
                {
                case Resource.Id.recommendations:
                    selectedFragment = new SearchUserFragment();
                    break;

                default:
                    selectedFragment = new ResultsTabFragment();
                    break;
                }

                try
                {
                    SupportFragmentManager
                    .BeginTransaction()
                    .Replace(Resource.Id.fragmentContainer, selectedFragment)
                    .Commit();

                    item.MenuItem.SetChecked(true);

                    _drawerLayout.CloseDrawers();
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Message);
                }
            };

            _navigationView.SetCheckedItem(Resource.Id.recommendations);
            try
            {
                SupportFragmentManager
                .BeginTransaction()
                .Replace(Resource.Id.fragmentContainer, new SearchUserFragment())
                .Commit();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }
        }