Exemplo n.º 1
0
        public override bool OnCreateOptionsMenu(IMenu menu)
        {
            // return base.OnCreateOptionsMenu(menu);
            MenuInflater.Inflate(Resource.Menu.actionmenu, menu);
            // var dd = menu.FindItem(Resource.Id.icon_group);
            IMenuItem     item = menu.FindItem(Resource.Id.ic_group);
            LayerDrawable icon = item.Icon as LayerDrawable;

            // LayerDrawable icon = (LayerDrawable)item.Icon;
            CountDrawable badge;
            Drawable      reuse = icon.FindDrawableByLayerId(Resource.Id.ic_group_count);

            if (reuse != null && reuse is CountDrawable)
            {
                badge = (CountDrawable)reuse;
            }
            else
            {
                badge = new CountDrawable(this);
            }
            badge.setCount("8");
            badge.GetBounds = icon.Bounds;

            icon.Mutate();
            icon.SetDrawableByLayerId(Resource.Id.ic_group_count, badge);
            return(true);
        }
Exemplo n.º 2
0
        Drawable CreateBackgroundForButton(bool renderImage = true)
        {
            List <Drawable> drawables         = new List <Drawable>();
            List <Drawable> drawablesDisabled = new List <Drawable>();

            drawables.Add(BackgroundExtension.CreateBackgroundGradient(button.StartColor.ToAndroid(),
                                                                       button.EndColor.ToAndroid(),
                                                                       button.CenterColor.ToAndroid(),
                                                                       button.CornerRadius,
                                                                       button.Angle.ToAndroid()));
            drawablesDisabled.Add(BackgroundExtension.CreateBackgroundGradient(button.StartColor.ToAndroid(),
                                                                               button.EndColor.ToAndroid(),
                                                                               button.CenterColor.ToAndroid(),
                                                                               button.CornerRadius,
                                                                               button.Angle.ToAndroid()));
            if (button.Image != null && !string.IsNullOrEmpty(button.Image.File) && renderImage)
            {
                var bitmapDrawable = BackgroundExtension.CreateBackgroundBitmap(button.Image.File, (int)button.HeightRequest,
                                                                                (int)button.WidthRequest, button.CornerRadius);
                if (bitmapDrawable != null)
                {
                    drawables.Add(bitmapDrawable);
                    drawablesDisabled.Add(bitmapDrawable);
                }
            }
            Drawable layer         = new LayerDrawable(drawables.ToArray());
            Drawable layerDisabled = new LayerDrawable(drawablesDisabled.ToArray());

            layerDisabled.Mutate().Alpha = 80;
            var statesListDrawable       = new StateListDrawable();

            statesListDrawable.AddState(new int[] { -Android.Resource.Attribute.StateEnabled }, layerDisabled);
            statesListDrawable.AddState(new int[] { Android.Resource.Attribute.StatePressed }, layer);
            statesListDrawable.AddState(new int[] { Android.Resource.Attribute.StateEnabled }, layer);
            return(statesListDrawable);
        }