示例#1
0
        public CommandBar(View parentView, int toolbarResource, HandleCommandDelegate handleDelegate)
        {
            // Save the command handling delegate
            commandDelegate = handleDelegate;

            // Create the toolbar
            Toolbar = parentView.FindViewById <Toolbar>(toolbarResource);

            if (Toolbar != null)
            {
                // Iterate through the children of this toolbar looking for ImageButton
                for (int index = 0; index < Toolbar.ChildCount; ++index)
                {
                    if (Toolbar.GetChildAt(index) is AppCompatImageButton imageButton)
                    {
                        // Get the name of the resource form the id and use it to form the name of the image resource
                        string[] packageSplit = Application.Context.Resources.GetResourceName(imageButton.Id).Split(':');
                        string   imageName    = string.Format("{0}:drawable/{1}", packageSplit[0], packageSplit[1].Split('/')[1]);

                        imageButton.SetImageResource(Application.Context.Resources.GetIdentifier(imageName, null, null));

                        // Store the button id and button in an hash table to enable them to be bound
                        Buttons.Add(imageButton.Id, imageButton);

                        imageButton.Click += ButtonClicked;
                    }
                }

                // Hide the toolbar initially
                Toolbar.Visibility = ViewStates.Gone;
            }
        }
示例#2
0
        void SetActionBarTextColor()
        {
            Color    navigationBarTextColor = CurrentNavigationPage == null ? Color.Default : CurrentNavigationPage.BarTextColor;
            TextView actionBarTitleTextView = null;

            if (Forms.IsLollipopOrNewer)
            {
                int actionbarId = _context.Resources.GetIdentifier("action_bar", "id", "android");
                if (actionbarId > 0)
                {
                    Toolbar toolbar = (Toolbar)((Activity)_context).FindViewById(actionbarId);

                    for (int i = 0; i < toolbar.ChildCount; i++)
                    {
                        if (toolbar.GetChildAt(i) is TextView)
                        {
                            actionBarTitleTextView = (TextView)toolbar.GetChildAt(i);
                            break;
                        }
                    }
                }
            }
            else
            {
                int actionBarTitleId = _context.Resources.GetIdentifier("action_bar_title", "id", "android");
                if (actionBarTitleId > 0)
                {
                    actionBarTitleTextView = ((Activity)_context).FindViewById <TextView>(actionBarTitleId);
                }
            }

            if (actionBarTitleTextView != null && navigationBarTextColor != Color.Default)
            {
                actionBarTitleTextView.SetTextColor(navigationBarTextColor.ToAndroid());
            }
            else if (actionBarTitleTextView != null && navigationBarTextColor == Color.Default)
            {
                actionBarTitleTextView.SetTextColor(_defaultActionBarTitleTextColor.ToAndroid());
            }
        }