Ejemplo n.º 1
0
        protected override void OnElementChanged(ElementChangedEventArgs <DropDownMenuView> e)
        {
            base.OnElementChanged(e);
            if (e.NewElement != null)
            {
                _dropDownView = (DropDownMenuView)e.NewElement;

                if (Control == null)
                {
                    Android.Widget.RelativeLayout wraper = new Android.Widget.RelativeLayout(Android.App.Application.Context);
                    ContextThemeWrapper           theme  = new ContextThemeWrapper(Android.App.Application.Context, Mobile.Droid.Resource.Style.Base_Widget_AppCompat_TextView_SpinnerItem);
                    _nativeView = new Spinner(theme);
                    _nativeView.OnItemSelectedListener = this;
                    if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.M)
                    {
                        _nativeView.SetBackgroundResource(Mobile.Droid.Resource.Drawable.abc_btn_borderless_material);
                    }
                    else
                    {
                        wraper.SetBackgroundResource(Mobile.Droid.Resource.Drawable.abc_btn_borderless_material);
                    }
                    _nativeView.LayoutParameters   = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);
                    _dropDownView.SetItemSelection = (i) =>
                    {
                        _nativeView.SetSelection(i);
                    };

                    ImageView downIcon = new ImageView(Android.App.Application.Context);
                    var       param    = new Android.Widget.RelativeLayout.LayoutParams(20, 20);
                    param.AddRule(LayoutRules.AlignParentRight);
                    param.AddRule(LayoutRules.CenterInParent);
                    param.SetMargins(0, 0, 14, 0);
                    downIcon.LayoutParameters = param;
                    downIcon.SetImageResource(Mobile.Droid.Resource.Drawable.abc_ic_arrow_drop_right_black_24dp);

                    wraper.AddView(_nativeView);
                    wraper.AddView(downIcon);
                    SetNativeControl(wraper);
                }

                if (_dropDownView.ItemsSource != null)
                {
                    SetApdater();
                }
            }
        }