【发布时间】:2019-07-25 20:44:50
【问题描述】:
我有一个 Xamarin.Forms 应用程序。我想删除/隐藏导航栏中的后退箭头,但保留标题。我可以在 iOS 中使用 NavigationPageRenderer 中的以下代码来完成此操作:
UINavigationBar.Appearance.BackIndicatorImage = new UIImage();
UINavigationBar.Appearance.BackIndicatorTransitionMaskImage = new UIImage();
在我的渲染器或 MainActivity 中,我可以在 Android 中使用任何等效的代码吗?我在MainActivity 中尝试了this.ActionBar.SetDisplayHomeAsUpEnabled(false);,但ActionBar 总是返回null。下面是我的 MainActivity 代码:
public class MainActivity : FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
if (Window != null)
{
Window.SetStatusBarColor(Android.Graphics.Color.Transparent);
}
this.ActionBar.SetDisplayHomeAsUpEnabled(false);
}
}
我希望我的导航栏看起来像下图(这是在我的 iOS 应用中)。
后退箭头就是后退按钮标题:NavigationPage.SetBackButtonTitle(this, "\u25C3");
在我的ContentPage:
public partial class HomeTabPage : ContentPage
{
public HomeTabViewModel vm;
public HomeTabPage()
{
InitializeComponent();
BindingContext = vm = new HomeTabViewModel(this);
NavigationPage.SetHasBackButton(this, false);
NavigationPage.SetBackButtonTitle(this, "\u25C3");
}
}
【问题讨论】:
-
这类似于
Page.HasBackButton = false。你可能必须投这个:ViewController.ParentViewController.NavigationItem.SetHidesBackButton(!((CustomContentPage)this.Element).HasBackButton, false); -
如果你的意思是
NavigationPage.SetHasBackButton(this, false);那么是的,我试过了,但没有用 -
调用 NavigationPage.SetHasBackButton(this, false) 时使用了哪个页面?如果你在 NavigationPage 上设置它,它不会做任何事情。
-
你能提供你想要的效果截图吗? NavigationPage.SetHasBackButton(this, false);如果你在 contentPage 中调用它应该可以工作。
-
我确实在我的 ContentPage 中调用了它
标签: xamarin xamarin.forms xamarin.android