public static Drawable FromDrawable(Drawable drawable, Resources r) { if (drawable != null) { if (drawable.GetType() == typeof(RoundedCornerDrawable)) { return(drawable); } else if (drawable.GetType() == typeof(LayerDrawable)) { LayerDrawable ld = drawable as LayerDrawable; int num = ld.NumberOfLayers; for (int i = 0; i < num; i++) { Drawable d = ld.GetDrawable(i); ld.SetDrawableByLayerId(ld.GetId(i), FromDrawable(d, r)); } return(ld); } Bitmap bm = DrawableToBitmap(drawable); if (bm != null) { return(new RoundedCornerDrawable(bm, r)); } } return(drawable); }
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); }
private void SetColor(ProgressBar bar, Color color) { LayerDrawable progressDrawable = (LayerDrawable)bar.ProgressDrawable; Drawable primaryColor = progressDrawable.GetDrawable(2); primaryColor.SetColorFilter(new LightingColorFilter(0, color)); progressDrawable.SetDrawableByLayerId(progressDrawable.GetId(2), new ClipDrawable(primaryColor, GravityFlags.Left, ClipDrawableOrientation.Horizontal)); }
public static void SetTheme(SeekBar seekBar, FlatTheme theme) { // setting thumb var thumb = new PaintDrawable(theme.DarkAccentColor); thumb.SetCornerRadius(15); thumb.SetIntrinsicWidth(30); thumb.SetIntrinsicHeight(30); seekBar.SetThumb(thumb); // progress var progress = new PaintDrawable(theme.BackgroundColor); progress.SetCornerRadius(10); progress.SetIntrinsicHeight(10); progress.SetIntrinsicWidth(5); progress.SetDither(true); var progressClip = new ClipDrawable(progress, GravityFlags.Left, ClipDrawableOrientation.Horizontal); // secondary progress var secondary = new PaintDrawable(theme.LightAccentColor); secondary.SetCornerRadius(10); secondary.SetIntrinsicHeight(10); var secondaryProgressClip = new ClipDrawable(secondary, GravityFlags.Left, ClipDrawableOrientation.Horizontal); // background PaintDrawable background = new PaintDrawable(theme.VeryLightAccentColor); background.SetCornerRadius(10); background.SetIntrinsicHeight(10); // applying drawable LayerDrawable ld = (LayerDrawable)seekBar.ProgressDrawable; ld.SetDrawableByLayerId(Android.Resource.Id.Background, background); ld.SetDrawableByLayerId(Android.Resource.Id.Progress, progressClip); ld.SetDrawableByLayerId(Android.Resource.Id.SecondaryProgress, secondaryProgressClip); }