예제 #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                MySearchBar Content = e.NewElement as MySearchBar;

                this.Control.SetBackgroundResource(Resource.Drawable.back_for_search);

                Android.Widget.SearchView searchView = (base.Control as Android.Widget.SearchView);

                int frameId = searchView.Context.Resources.GetIdentifier("android:id/search_plate", null, null);
                Android.Views.View frameView = (searchView.FindViewById(frameId) as Android.Views.View);
                frameView.SetBackgroundColor(Xamarin.Forms.Color.Transparent.ToAndroid());
//				frameView.SetBackgroundResource(Resource.Drawable.textfield_searchview_holo_light);


                // Get native control (background set in shared code, but can use SetBackgroundColor here)
                searchView.SetInputType(InputTypes.ClassText | InputTypes.TextVariationNormal);

                // Access search textview within control
                int      textViewId = searchView.Context.Resources.GetIdentifier("android:id/search_src_text", null, null);
                EditText textView   = (searchView.FindViewById(textViewId) as EditText);
//				textView.SetBackgroundResource(Resource.Drawable.textfield_searchview_holo_light);

                // Set custom colors

//				textView.SetBackgroundColor( Android.Graphics.Color.White );
//				textView.SetTextColor( G.Color.Rgb( 32, 32, 32 ) );
//				textView.SetHintTextColor( G.Color.Rgb( 128, 128, 128 ) );

//				// Customize frame color
//				int frameId = searchView.Context.Resources.GetIdentifier( "android:id/search_plate", null, null );
//				Android.Views.View frameView = (searchView.FindViewById( frameId ) as Android.Views.View);
//				frameView.SetBackgroundColor( G.Color.Rgb( 96, 96, 96 ) );



//				SetBackgr (this.Control);
            }
        }
		private void InitView()
		{
			//设置标题栏
			var btn_header_back = FindViewById<Button> (Resource.Id.btn_header_back);
			btn_header_back.Click += (sender, e) => 
			{
				this.Finish();
			};

			FindViewById<TextView> (Resource.Id.tv_header_title).Text = "监护人绑定";

			listView = FindViewById<ListView> (Resource.Id.lv_searchGuardian);


		    searchView = FindViewById<SearchView> (Resource.Id.searchView);
			searchView.SetOnQueryTextListener (this);
			//设置searchview中textview颜色
			var id = searchView.Context.Resources.GetIdentifier ("android:id/search_src_text", null, null);
			textView = (TextView)searchView.FindViewById(id);
			textView.SetTextColor (Resources.GetColor (Resource.Color.lightgray));

			//查询
			var txt_Querry = FindViewById<TextView> (Resource.Id.txt_Querry);
			txt_Querry.Click += (sender, e) => 
			{
				OnQueryTextSubmit(textView.Text);
			};

			applyGuardianListAdapter = new ApplyGuardianListAdapter (this);
			applyGuardianListAdapter.RefreshAction = () => {
				QuerryBindGuardian(textView.Text);
			};
			listView.Adapter = applyGuardianListAdapter;
			//设置滑动listview停止加载图片
			listView.SetOnScrollListener (new PauseOnScrollListener(Global.imageLoader,false,false));
		}
예제 #3
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.SearchBar> e)
        {
            base.OnElementChanged(e);

            var element = (MvvmAspire.Controls.SearchBar)Element;

            // Get native control (background set in shared code, but can use SetBackgroundColor here)
            Android.Widget.SearchView searchView = (base.Control as Android.Widget.SearchView);
            searchView.SetInputType(InputTypes.ClassText | InputTypes.TextVariationNormal);

            int textViewId = searchView.Context.Resources.GetIdentifier("android:id/search_src_text", null, null);

            editText = (searchView.FindViewById(textViewId) as EditText);
            editText.SetTextColor(element.TextColor.ToAndroid());
            //editText.TextAlignment = Android.Views.TextAlignment.
            editText.Gravity = GravityFlags.CenterVertical | GravityFlags.Start;

            if (element.PlaceholderColor != Xamarin.Forms.Color.Default)
            {
                editText.SetHintTextColor(element.PlaceholderColor.ToAndroid());
            }

            //if (element.ShowSearchIconAsPlaceHolder)
            //    editText.SetCompoundDrawablesRelativeWithIntrinsicBounds(Android.Resource.Drawable.IcMenuSearch, 0, 0, 0);

            //editText.TextChanged += editText_TextChanged;

            int          searchPlateId     = searchView.Context.Resources.GetIdentifier("android:id/search_plate", null, null);
            LinearLayout searchPlateLayout = (searchView.FindViewById(searchPlateId) as LinearLayout);

            //searchPlateLayout.SetBackgroundColor(Android.Graphics.Color.Red);

            if (element.Background != null && element.Background.File != null)
            {
                searchPlateLayout.SetBackgroundResource(UIHelper.GetDrawableResource(element.Background));
            }
            else
            {
                if (element.BackgroundColor != Xamarin.Forms.Color.Default)
                {
                    searchPlateLayout.SetBackgroundColor(element.BackgroundColor.ToAndroid());
                }
            }

            int frameId = searchView.Context.Resources.GetIdentifier("android:id/search_edit_frame", null, null);
            //Android.Views.View frameView = (searchView.FindViewById(frameId) as Android.Views.View);
            LinearLayout frameView = (searchView.FindViewById(frameId) as LinearLayout);

            if (element.Background != null && element.Background.File != null)
            {
                frameView.SetBackgroundResource(UIHelper.GetDrawableResource(element.Background));
            }

            int       searchIconId = searchView.Context.Resources.GetIdentifier("android:id/search_mag_icon", null, null);
            ImageView searchIcon   = (searchView.FindViewById(searchIconId) as ImageView);

            if (element.SearchIcon != null && element.SearchIcon.File != null)
            {
                searchIcon.SetImageResource(UIHelper.GetDrawableResource(element.SearchIcon));
            }
            else
            {
                searchIcon.SetImageResource(Android.Resource.Drawable.IcMenuSearch);
            }

            if (element.AlignSearchIconRight)
            {
                searchIcon.LayoutParameters = new LinearLayout.LayoutParams(0, 0);

                var iv = new ImageView(this.Context);
                iv.Click += (s, ev) =>
                {
                    if (Element.SearchCommand != null && Element.SearchCommand.CanExecute(Element.SearchCommandParameter))
                    {
                        Element.SearchCommand.Execute(Element.SearchCommandParameter);
                    }
                };

                if (searchIcon.Drawable != null)
                {
                    iv.SetImageDrawable(searchIcon.Drawable);
                }

                frameView.AddView(iv);

                this.SetBackgroundColor(Android.Graphics.Color.Transparent);
            }


            int       search_close_btnID = searchView.Context.Resources.GetIdentifier("android:id/search_close_btn", null, null);
            ImageView search_close_btn   = (searchView.FindViewById(search_close_btnID) as ImageView);

            search_close_btn.Click += search_close_btn_Click;

            SetTextInputTypes(element);
            search_close_btn.SetImageResource(Android.Resource.Drawable.IcMenuCloseClearCancel);

            //if (GetThemeName() == Android.Resource.Style.ThemeMaterialLightDarkActionBar)
            //{

            //}

            CreateShapeDrawable(element);
            SetTypeface();
            //if (element.HeightRequest > 0)
            //{
            //    editText.SetHeight(BaseUIHelper.ConvertDPToPixels(element.HeightRequest));
            //}
        }