【发布时间】:2016-03-14 23:07:31
【问题描述】:
我需要在我的 Xamarin Android 项目中自定义操作栏和选项卡片段。 因为我有自定义操作栏,我需要关闭原来的操作栏,所以这是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="pitsapp1x.pitsapp1x" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="16" />
<application android:theme="@android:style/Theme.NoTitleBar"></application>
</manifest>
现在在我的选项卡上,它需要 ActionBar.NavigationMode
public class frmTab : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.frmTab);
HERE>>> this.ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
AddTab("Buy", Resource.Drawable.Icon, new frmTabBuy());
AddTab("Home", Resource.Drawable.Icon, new frmTabHome());
}
private void AddTab(string tabText, int iconResourceId, Fragment fragment)
{
HERE>>> var tab = this.ActionBar.NewTab();
tab.SetText(tabText);
tab.SetIcon(iconResourceId);
tab.TabSelected += delegate(object sender, ActionBar.TabEventArgs e)
{
e.FragmentTransaction.Replace(Resource.Id.fragmentContainer, fragment);
};
HERE>>> this.ActionBar.AddTab(tab);
}
导致结果一直返回给我
System.NullReferenceException: Object reference not set to an instance of an object
我有什么解决方案可以链接到我的自定义操作栏或不使用操作栏吗?感谢您的帮助...
【问题讨论】:
标签: android xamarin tabs android-actionbar