我正在尝试在MVVMCross Xamarin Adroid应用程序中使用ActionBar。我能够在片段中加载布局,问题是上下文总是指向MainView而不是布局视图。我试图更改上下文,但资源异常。错误是
Java.Lang.NullPointerException:尝试在 null 对象引用上调用虚拟方法 'android.content.res.Resources android.content.Context.getResources()'
代码片段
公共类LocationFragment:Fragment{公共重写视图OnCreateView(LayoutFlater充气机、ViewGroup容器、捆绑包savedInstanceState){
//View view = inflater.Inflate(Resource.Layout.Location, null);
View view = inflater.CloneInContext(new LocationView().BaseContext).Inflate(Resource.Layout.Location, null);
return view;
}
}
一位Android本地开发人员告诉我,我无法更改上下文,因为视图总是从MainActivity驱动。如果是这样的话,我怎么能用它来表达我的观点呢?
ActionBar已弃用。您可能应该使用工具栏,MvvmCross提供了包含片段支持的示例:https://github.com/MvvmCross/MvvmCross-AndroidSupport/tree/master/Samples