Android MvvmCross&x2B;Monodroid应用程序的ActionBar
我正在使用Xamarin和MvvmCross编写monodroid应用程序 我想在我的应用程序中同时使用MvvmCross和ActionBar。 ActionBar(Legacy或Sherlock)强迫我继承他们的自定义活动。 在这种情况下,我无法从MVXAActivity和CustomBarActivity继承我的活动Android MvvmCross&x2B;Monodroid应用程序的ActionBar,android,android-actionbar,xamarin.android,xamarin,mvvmcross,Android,Android Actionbar,Xamarin.android,Xamarin,Mvvmcross,我正在使用Xamarin和MvvmCross编写monodroid应用程序 我想在我的应用程序中同时使用MvvmCross和ActionBar。 ActionBar(Legacy或Sherlock)强迫我继承他们的自定义活动。 在这种情况下,我无法从MVXAActivity和CustomBarActivity继承我的活动 如何使用Mvx活动显示动作栏?我以类似Mvx的方式实现动作栏的做法是,我在TabActivity中创建了一个属性,以便访问ViewModel。在我的ViewModel中,我有一
如何使用Mvx活动显示动作栏?我以类似Mvx的方式实现动作栏的做法是,我在TabActivity中创建了一个属性,以便访问ViewModel。在我的ViewModel中,我有一个可以枚举和创建的actionbar元素列表。我确信有更多类似MvvMcross的方法来实现actionbar(问问stuart),但这对我来说效果很好。别忘了让您的活动继承自TabActivity 财产:
protected MvvMAppiAppi.Core.ViewModels.NavigationBarViewModel NavigationBarViewModel {
get{ return base.ViewModel as MvvMAppiAppi.Core.ViewModels.NavigationBarViewModel; }
}
代码:
用于创建选项卡的函数:
private void setUpTab (Intent view, string tag, int Resource)
{
View tabview = createTabView (this.TabHost.Context, tag, Resource);
TabHost.TabSpec spec = this.TabHost.NewTabSpec (tag).SetIndicator (tabview).SetContent (view);
this.TabHost.AddTab (spec);
}
private View createTabView (Context context, String text, int resource)
{
View view = LayoutInflater.From (context).Inflate (Resource.Layout.tabs_bg, null);
TextView tv = view.FindViewById<TextView> (Resource.Id.tabsText);
ImageView iv = view.FindViewById<ImageView> (Resource.Id.image);
iv.SetImageResource (resource);
tv.SetText (text, TextView.BufferType.Normal);
return view;
}
private void设置选项卡(意图视图、字符串标记、int资源)
{
视图选项卡视图=createTabView(this.TabHost.Context、标记、资源);
TabHost.TabSpec spec=this.TabHost.NewTabSpec(tag).SetIndicator(tabview).SetContent(view);
this.TabHost.AddTab(spec);
}
私有视图createTabView(上下文、字符串文本、int资源)
{
View-View=LayoutFlater.From(上下文)。充气(Resource.Layout.tabs\u bg,空);
TextView tv=view.findviewbyd(Resource.Id.tabsText);
ImageView iv=view.findviewbyd(Resource.Id.image);
iv.SetImageResource(资源);
tv.SetText(text,TextView.BufferType.Normal);
返回视图;
}
可能重复@stuart,不重复-actionbar夏洛克和actionbar不同
private void setUpTab (Intent view, string tag, int Resource)
{
View tabview = createTabView (this.TabHost.Context, tag, Resource);
TabHost.TabSpec spec = this.TabHost.NewTabSpec (tag).SetIndicator (tabview).SetContent (view);
this.TabHost.AddTab (spec);
}
private View createTabView (Context context, String text, int resource)
{
View view = LayoutInflater.From (context).Inflate (Resource.Layout.tabs_bg, null);
TextView tv = view.FindViewById<TextView> (Resource.Id.tabsText);
ImageView iv = view.FindViewById<ImageView> (Resource.Id.image);
iv.SetImageResource (resource);
tv.SetText (text, TextView.BufferType.Normal);
return view;
}