Forum Xamarin Xamarin.Forms

SearchBarRenderer - Here's how to customize it in Android

IanVinkIanVink CAInsider, University ✭✭✭
edited December 2014 in Xamarin.Forms

For more detailed other options, this is handy:

   [assembly: ExportRenderer(typeof (CustomSearchBar), typeof (CustomSearchBarRenderer))]

  namespace Bahai.Android.Renderers
    public class CustomSearchBarRenderer : SearchBarRenderer
    protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
        if (e.OldElement == null)
            SearchBar element = (SearchBar) this.Element;
            var native = (global::Android.Widget.SearchView) Control;

            // do whatever you want to the controls here!
            // element.BackgroundColor = Color.Transparent;
            // native.SetBackgroundColor(element.BackgroundColor.ToAndroid());
            // native.SetBackgroundColor(Color.White.ToAndroid());

            //The text color of the SearchBar / SearchView 
            AutoCompleteTextView textField = (AutoCompleteTextView)
                (((Control.GetChildAt(0) as ViewGroup)
                    .GetChildAt(2) as ViewGroup)
                    .GetChildAt(1) as ViewGroup)

            if (textField != null)
Sign In or Register to comment.