Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

SearchBarRenderer - Here's how to customize it in Android

$
0
0

For more detailed other options, this is handy: http://stackoverflow.com/questions/25626364/textcolor-of-xamarin-forms-searchbar/27683185#27683185

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

  namespace Bahai.Android.Renderers
  {
    public class CustomSearchBarRenderer : SearchBarRenderer
  {
    protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
    {
        base.OnElementChanged(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)
                    .GetChildAt(0);

            if (textField != null)
                textField.SetTextColor(Color.White.ToAndroid());
        }
    }
  }
  }

Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>