【问题标题】:Xamarin hide hamburger menu barXamarin 隐藏汉堡菜单栏
【发布时间】:2018-11-09 09:31:10
【问题描述】:

我正在尝试从汉堡菜单中隐藏该栏,并仅保留 Uber App 之类的图标按钮。

我有一个默认的母版页详细结构,我尝试了多种解决方案:

1 - 在 App.xaml 中

<ResourceDictionary>           
        <Style TargetType="NavigationPage">
            <Setter Property="BarBackgroundColor" Value="Transparent"/>
            <Setter Property="BarTextColor" Value="Red"/>
        </Style>              
</ResourceDictionary>

2 - MasterDetailPageRenderer

public class CustomMasterDetailRenderer : MasterDetailPageRenderer
{
    public CustomMasterDetailRenderer(Android.Content.Context context):base(context)
    {

    }
    protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
    {
        base.OnLayout(changed, left, top, right, bottom);          
        var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
        if (toolbar != null)
        {               
            toolbar.SetBackgroundColor(Android.Graphics.Color.Argb(0, 0, 0, 0));
        }            
    }
}

不幸的是,得到了这个结果:

【问题讨论】:

  • 你是如何隐藏你的工具栏而只显示菜单按钮的?
  • 我问的问题...怎么做...阅读@HeikkiDev 答案
  • 是的,我现在知道了。

标签: c# xamarin xamarin.forms


【解决方案1】:

您可以使用 (XAML) 隐藏此页面中的导航栏:

NavigationPage.HasNavigationBar="False"

并添加您自己的带有点击手势识别器的汉堡图标来处理菜单可见性:

MasterDetailPage masterDetailRootPage = (MasterDetailPage)Application.Current.MainPage;
masterDetailRootPage.IsPresented = true;

【讨论】:

    【解决方案2】:

    以编程方式隐藏和显示汉堡图标

    隐藏/禁用

    NavigationPage.SetHasNavigationBar(this, false);
    

    显示/启用

    NavigationPage.SetHasNavigationBar(this, true);
    

    【讨论】:

    • 这个答案的意义为零。如果您隐藏导航栏,您将没有导航
    猜你喜欢
    • 2021-10-20
    • 2019-04-19
    • 2021-02-17
    • 2018-08-16
    • 1970-01-01
    • 2021-11-29
    • 1970-01-01
    • 2017-05-04
    相关资源
    最近更新 更多