protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> e) { base.OnElementChanged(e); if (e.OldElement == null && Element != null) { // WorkAround to searchBar not appearing in newer android versions if (Build.VERSION.SdkInt >= BuildVersionCodes.N) { Element.HeightRequest = 40; } } if (Control != null && Element != null) { var plate = Control.FindViewById(base.Resources.GetIdentifier("android:id/search_plate", null, null)); plate.Background = new ColorDrawable(Android.Graphics.Color.Transparent); Control.Background = ContextCompat.GetDrawable(Android.App.Application.Context, Resource.Drawable.RoundedBackground); //Control.SetPadding(20, 20, 20, 20); Control.TextAlignment = Android.Views.TextAlignment.Gravity; var listener = new OnQueryTextListener(Element); Control.SetOnQueryTextListener(listener); EditText searchPlate = Control.FindViewById <EditText>(base.Resources.GetIdentifier("android:id/search_src_text", null, null)); searchPlate.SetOnEditorActionListener(new OnEditorActionListener(listener)); } }
protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> e) { base.OnElementChanged(e); if (e.OldElement == null && Element != null) { // WorkAround to searchBar not appearing in newer android versions if (Build.VERSION.SdkInt >= BuildVersionCodes.N) { Element.HeightRequest = 40; } } if (Control != null && Element != null) { var listener = new OnQueryTextListener(Element); Control.SetOnQueryTextListener(listener); EditText searchPlate = Control.FindViewById <EditText>(base.Resources.GetIdentifier("android:id/search_src_text", null, null)); searchPlate.SetOnEditorActionListener(new OnEditorActionListener(listener)); } }
public OnEditorActionListener(OnQueryTextListener listener) { this.listener = listener; }