您的当前位置:首页正文

Xamarin状态栏自定义

来源:要发发知识网

刚入手Xamarin的时候,由于文档信息量太大,走了很多弯路,其中一个就是APP设计中常见的问题,默认的状态栏是固定的,左边是返回,右边可以加个按钮,有时候我们想往里面加个搜索框、选择框之类通过需要加Redender才可以,自从Xamarin.Forms升级到3.2之后,增加了一个新的标签叫做NavigationPage.TitleView,这意味着状态栏可编辑的空间就变大了,例如修改高度、字体大小、颜色、增加组件。

此标签应该在ContentPage.Content之前,具体的代码可以参考如下

<NavigationPage.TitleView>

        <StackLayout Orientation="Horizontal" HorizontalOptions="Fill" VerticalOptions="Fill" Spacing="10">

            <Label x:Name="btBack" VerticalOptions="Center" HorizontalOptions="Start" WidthRequest="40" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" FontSize="{local:FixFontSize 24}" Text="&#xe618;" Style="{StaticResource IconFont}" TextColor="White">

                <Label.GestureRecognizers>

                    <TapGestureRecognizer NumberOfTapsRequired="1" Tapped="BtBack_Tapped" />

                </Label.GestureRecognizers>

            </Label>

            <Label VerticalOptions="Center" x:Name="lbName" HorizontalOptions="FillAndExpand" FontSize="{local:FixFontSize 18}" Text="水单明细" TextColor="White" />

            <Label x:Name="btAdd" VerticalOptions="Center" HorizontalOptions="End" WidthRequest="60" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" FontSize="{local:FixFontSize 18}" Text="&#xe616;" Style="{StaticResource IconFont}" TextColor="White">

                <Label.GestureRecognizers>

                    <TapGestureRecognizer NumberOfTapsRequired="1" />

                </Label.GestureRecognizers>

            </Label>

        </StackLayout>

    </NavigationPage.TitleView>