我正在开发 Xamarin Android应用程序。我有三个片段,其中一个是BaseFragment。我把Toolbar和Drawerview放在基本片段中。现在,当我转到下一个片段时,我想更改菜单项并想要隐藏抽屉图标。如何做到这一点,任何想法?
我已尝试SetDisplayHomeAsUpEnabled(false)
,SetHomeButtonEnabled(false)
和SetDisplayShowHomeEnabled(false)
隐藏抽屉图标,但它没有效果。
public abstract class BaseFragment : MvxFragment
{
private Toolbar _toolbar;
private MvxActionBarDrawerToggle _drawerToggle;
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var ignore = base.OnCreateView(inflater, container, savedInstanceState);
var view = this.BindingInflate(FragmentId, null);
_toolbar = view.FindViewById<Toolbar>(Resource.Id.toolbar);
if (_toolbar != null)
{
((MainActivity)Activity).SetSupportActionBar(_toolbar);
((MainActivity)Activity).SupportActionBar.SetDisplayHomeAsUpEnabled(false);
_drawerToggle = new MvxActionBarDrawerToggle(
Activity, // host Activity
((MainActivity)Activity).DrawerLayout, // DrawerLayout object
_toolbar, // nav drawer icon to replace 'Up' caret
Resource.String.drawer_open, // "open drawer" description
Resource.String.drawer_close // "close drawer" description
);
((MainActivity)Activity).DrawerLayout.SetDrawerListener(_drawerToggle);
}
return view;
}
protected abstract int FragmentId { get; }