如何在Xamarin表单中自定义导航栏中的搜索栏

时间:2017-10-12 06:10:12

标签: xamarin xamarin.forms

我尝试在Xamarin.android和Xamarin.Ios的导航栏中添加搜索栏。我试过下面的帖子它的工作'但我想自定义搜索栏文本颜色和搜索栏图像。你能提出任何想法吗?

我尝试了链接:https://www.linkedin.com/pulse/xamarin-forms-contentpage-searchbar-navigation-bar-vipin-mathews

enter image description here

当我应用上面的链接代码时,我得到这样的导航栏,当用户点击搜索图像时,搜索栏将出现在导航栏中。在上面的导航栏中,点图像是工具栏图像设置顺序是' Primary'。我的要求是首先显示搜索图像,然后在显示工具栏图像后,在上图中准确地交换搜索图像的位置。我怎样才能做到这一点。

2 个答案:

答案 0 :(得分:2)

使用ToolbarItem的Priority属性定义从左到右的顺序,而不是Ordering属性。我知道,根本不会混淆!

<ContentPage.ToolbarItems>
    <ToolbarItem Name="SearchItem" Icon="search.png" Priority="0" />
    <ToolbarItem Name="MoreItem" Icon="more.png" Priority="1" />
</ContentPage.ToolbarItems>

Read this great blog post about the Xamarin Forms Toolbar for more details

答案 1 :(得分:0)

请使用此库。

SNavigationPage

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:snav="clr-namespace:Stormlion.SNavigation;assembly=Stormlion.SNavigation"
             x:Class="Test.Page1"
             >
    <snav:SNavigationPage.NavContent>
        <Grid Margin="50, 0, 50, 0"
              >
            <SearchBar BackgroundColor="White"
                       Placeholder="Search ..."
                       />
        </Grid>
    </snav:SNavigationPage.NavContent>
    <ContentPage.Content>
        ...
    </ContentPage.Content>
</ContentPage>
相关问题