예제 #1
0
 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;
     }
 }
예제 #2
0
        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);
        }
예제 #3
0
 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);
     }
 }
예제 #4
0
 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);
 }
예제 #5
0
        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);
        }