コード例 #1
0
        /// <summary>
        /// Set defaults value.
        /// </summary>
        void SetDefaultValue()
        {
            // TextProperty
            nativeButton.SetText(fixedButton.Text, Android.Widget.TextView.BufferType.Normal);
            nativeButton.TextAlignment = Android.Views.TextAlignment.Center;

            // TextColorProperty
            nativeButton.SetTextColor(fixedButton.TextColor.ToAndroid());

            // ButtonBackgroundColorProperty
            nativeButton.SetBackgroundColor(fixedButton.ButtonBackgroundColor.ToAndroid());
        }
コード例 #2
0
        private async Task SetImageSourceAsync(Android.Widget.Button targetButton, ImageButton model)
        {
            if (targetButton == null || targetButton.Handle == IntPtr.Zero || model == null)
            {
                return;
            }

            var source = model.IsEnabled ? model.Source : model.DisabledSource ?? model.Source;

            using (var bitmap = await GetBitmapAsync(source))
            {
                if (bitmap == null)
                {
                    targetButton.SetCompoundDrawables(null, null, null, null);
                }
                else
                {
                    var drawable = new BitmapDrawable(bitmap);
                    using (var scaledDrawable = GetScaleDrawable(drawable, GetWidth(model.ImageWidthRequest), GetHeight(model.ImageHeightRequest)))
                    {
                        Drawable left    = null;
                        Drawable right   = null;
                        Drawable top     = null;
                        Drawable bottom  = null;
                        int      padding = 5;
                        targetButton.CompoundDrawablePadding = RequestToPixels(padding);
                        switch (model.Orientation)
                        {
                        case ImageOrientation.ImageToLeft:
                            targetButton.Gravity = GravityFlags.Left | GravityFlags.CenterVertical;
                            left = scaledDrawable;
                            break;

                        case ImageOrientation.ImageToRight:
                            targetButton.Gravity = GravityFlags.Right | GravityFlags.CenterVertical;
                            right = scaledDrawable;
                            break;

                        case ImageOrientation.ImageOnTop:
                            targetButton.Gravity = GravityFlags.Top | GravityFlags.CenterHorizontal;
                            top = scaledDrawable;
                            break;

                        case ImageOrientation.ImageOnBottom:
                            targetButton.Gravity = GravityFlags.Bottom | GravityFlags.CenterHorizontal;
                            bottom = scaledDrawable;
                            break;

                        case ImageOrientation.ImageCentered:
                            targetButton.Gravity = GravityFlags.Center;
                            top = scaledDrawable;
                            break;
                        }

                        targetButton.SetCompoundDrawables(left, top, right, bottom);
                        targetButton.SetBackgroundColor(Android.Graphics.Color.Transparent);
                    }
                }
            }
        }
コード例 #3
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);
            Android.Widget.Button thisButton  = Control as Android.Widget.Button;
            FancyButton           formsButton = (FancyButton)Element;

            _pressedDownColor = formsButton.PressedDownColor;
            thisButton.Touch += (object sender, Android.Views.View.TouchEventArgs e2) => {
                if (e2.Event.Action == MotionEventActions.Down)
                {
                    thisButton.SetBackgroundColor(_pressedDownColor.ToAndroid());
                }
                else if (e2.Event.Action == MotionEventActions.Up)
                {
                    thisButton.SetBackgroundColor(Xamarin.Forms.Color.Default.ToAndroid());
                }
            };
        }