【问题标题】:Where is whitespace between burger icon and search bar coming from?汉堡图标和搜索栏之间的空白来自哪里?
【发布时间】:2021-02-12 12:45:37
【问题描述】:

如何让 SearchBar 立即出现在汉堡包图标的右侧(请参见图片),白色空间来自哪里?我找不到它。

Iv 将 NavigationPage 中的 stackLayout 和 SearchBar 设置为 `Horizo​​ntalOptions="StartAndExpand" VerticalOptions="StartAndExpand"

它来自 burgerIcon 按钮的填充。怎么查,代码里也找不到?

感谢任何回复

 <?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"x:Class="WineShop.Views.Products">
    <NavigationPage.TitleView>
        <StackLayout HorizontalOptions="StartAndExpand" VerticalOptions="StartAndExpand" Orientation="Horizontal">
            <SearchBar x:Name="SearchBar" TextChanged="SearchBar_TextChanged" HorizontalOptions="StartAndExpand" Placeholder="Search..." PlaceholderColor="Gray" TextColor="White" VerticalOptions="StartAndExpand"/>
        </StackLayout>
    </NavigationPage.TitleView>
    <ContentPage.ToolbarItems>
        <ToolbarItem Name="shoppingCartImg" Icon="shoppingCartImg.png" Priority="0" Order="Primary" Activated="ShoppingCartClicked"/>
        <ToolbarItem Text="{Binding NoItemsInShoppingCart}" Priority="0" Order="Primary" Activated="ShoppingCartClicked"/>
    </ContentPage.ToolbarItems>
    <ContentPage.Content>
        <Grid>

【问题讨论】:

  • 汉堡按钮是如何定义的?
  • 我不确定,当您使用“主详细信息”模板创建新项目时,它会预加载。所以我不确定它在哪里定义

标签: xaml xamarin xamarin.forms searchbar


【解决方案1】:

尝试将以下行添加到您的Toolbar.xml

app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"

【讨论】:

  • 这样做并将 StackLayout 和 SearchBar 的 Horizo​​ntalOptions 设置为 FillAndExpand 解决了这个问题,非常感谢 Leo 的帮助