private void UpdateButtonIcon(Android.Widget.ImageButton cellButton, string icon) { if (string.IsNullOrWhiteSpace(icon)) { cellButton.Visibility = ViewStates.Gone; } else { cellButton.SetImageDrawable(_Context.GetDrawable(icon)); cellButton.SetImageDrawable(_Context.GetDrawable(icon)); cellButton.Visibility = ViewStates.Visible; } }
AImageButton CreateImageButton(Context context, BindableObject bindable, BindableProperty property, int defaultImage, int leftMargin, int rightMargin, string tag) { var result = new AImageButton(context); result.Tag = tag; result.SetPadding(0, 0, 0, 0); result.Focusable = false; result.SetScaleType(ImageView.ScaleType.FitCenter); if (bindable.GetValue(property) is ImageSource image) { AutomationPropertiesProvider.SetContentDescription(result, image, null, null); } ((ImageSource)bindable.GetValue(property)).LoadImage(MauiContext, (r) => { result.SetImageDrawable(r?.Value); }); var lp = new LinearLayout.LayoutParams((int)Context.ToPixels(22), LP.MatchParent) { LeftMargin = leftMargin, RightMargin = rightMargin }; result.LayoutParameters = lp; lp.Dispose(); result.SetBackground(null); return(result); }
async void SetImage(AImageButton button, ImageSource image, int defaultValue) { button.SetScaleType(ImageView.ScaleType.FitCenter); if (image != null) { using (var drawable = await Context.GetFormsDrawable(image)) button.SetImageDrawable(drawable); } else if (defaultValue > 0) { await Task.Run(() => button.SetImageResource(defaultValue)).ConfigureAwait(false); } else { button.SetImageDrawable(null); } }
private void ChangeIcon(Android.Widget.ImageButton imageButton, int id) { if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { imageButton.SetImageDrawable(Context.GetDrawable(id)); } imageButton.SetImageResource(id); }
AImageButton CreateImageButton(Context context, BindableObject bindable, BindableProperty property, int defaultImage, int leftMargin, int rightMargin, string tag) { var result = new AImageButton(context); result.Tag = tag; result.SetPadding(0, 0, 0, 0); result.Focusable = false; result.SetScaleType(ImageView.ScaleType.FitCenter); string defaultHint = null; string defaultDescription = null; if (bindable.GetValue(property) is ImageSource image) { AutomationPropertiesProvider.SetContentDescription(result, image, ref defaultDescription, ref defaultHint); } _shellContext.ApplyDrawableAsync(bindable, property, drawable => { if (drawable != null) { result.SetImageDrawable(drawable); } else if (defaultImage > 0) { result.SetImageResource(defaultImage); } else { result.SetImageDrawable(null); } }); var lp = new LinearLayout.LayoutParams((int)Context.ToPixels(22), LP.MatchParent) { LeftMargin = leftMargin, RightMargin = rightMargin }; result.LayoutParameters = lp; lp.Dispose(); result.SetBackground(null); return(result); }