Search code examples
xamarin.formsxamarin.android

What is the best way to place a SearchBar inside of your NavigationBar?


What is the best way to place a SearchBar inside of your NavigationBar for an android app?


Solution

  • What is the best way to place a SearchBar inside of your NavigationBar?

    The TitleView could help you display the SearchBar in the navigation bar easily.

    Check the code:

    <ContentPage ...>
        <NavigationPage.TitleView>
            <<SearchBar Text="testing for search bar"/>
        </NavigationPage.TitleView>
        ...
    </ContentPage>
    

    Update:

    Page.xaml

    <local:CustomPage 
        ...
        xmlns:local="clr-namespace:App19F_5"
        x:Class="App19F_5.Page6">
    
        ...
    </local:CustomPage>
    

    Page.xaml.cs

    public partial class Page6 : CustomPage
    {
        ...
    }
    

    CustomPage.xaml

    <ContentPage ... x:Class="App19F_5.CustomPage">
        <NavigationPage.TitleView>
            <SearchBar />
        </NavigationPage.TitleView>
    </ContentPage>