0

Currently, I'm using these AppThemeColors.

<AppThemeColor x:Key="PrimaryColor"
               Light="Teal"
               Dark="Indigo"/>

<AppThemeColor x:Key="SecondaryColor"
               Light="White"
               Dark="Black"/>

How can I change the color of the SearchBar icon and underline using these AppThemeColors?

Saamer
  • 4,687
  • 1
  • 13
  • 55
Hrodlfr
  • 41
  • 6
  • We need to use Custom Renderer to customize the search bar . Check https://stackoverflow.com/questions/52368039/changing-searchview-search-icon-xamarin-android . – Lucas Zhang Jun 17 '20 at 14:51

1 Answers1

1

There is an issue on iOS 13 onwards in the search bar for iOS. According to the issue filed in Xamarin's GitHub, you can use a PlatformEffect to implement that:

public class SearchBarBackgroundEffect : PlatformEffect
{
    public SearchBarBackgroundEffect()
    {
    }

    private UIKit.UISearchBar NativeSearchBar => (UIKit.UISearchBar)Control;
    private SearchBar XamarinSearchBar => (SearchBar)Element;

    protected override void OnAttached()
    {
        if (UIKit.UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
            NativeSearchBar.SearchTextField.BackgroundColor = XamarinSearchBar.BackgroundColor.ToUIColor();
    }
    protected override void OnDetached()
    {

    }
}
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Saamer
  • 4,687
  • 1
  • 13
  • 55