如何在Xamarin Android中更新TabHost指示器

如何在Xamarin Android中更新TabHost指示器,android,xamarin,android-tabhost,Android,Xamarin,Android Tabhost,我需要动态更改选项卡指示器。我可以在Java中找到答案,但在Xamarin中找不到。我尝试使用java代码,但没有成功。这是我的密码 布局代码: <LinearLayout android:layout_width="match_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/llche

我需要动态更改选项卡指示器。我可以在Java中找到答案,但在Xamarin中找不到。我尝试使用java代码,但没有成功。这是我的密码

布局代码:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"   
        android:orientation="vertical"
        android:id="@+id/llcheckoutmiddle"
        android:layout_below="@id/llcheckouttop">
        <TabHost
            android:minWidth="25px"
            android:minHeight="25px"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/tabHostChkOut">
            <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:id="@+id/linearLayout1">
               <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="50dp" />
                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
            </LinearLayout>
        </TabHost>
    </LinearLayout>
            LocalActivityManager localActMgr = new LocalActivityManager(this, false);
            localActMgr.DispatchCreate(bundle);

            TabHost tabHost = FindViewById<TabHost>(Resource.Id.tabHostChkOut);
            tabHost.Setup(localActMgr);

            TabHost.TabSpec tabSpec = null;
            Intent intent = new Intent();

            intent = new Intent();
            intent.SetFlags(ActivityFlags.NewTask);
            intent.SetClass(this, typeof(RouteCheckoutExc));
            tabSpec = tabHost.NewTabSpec("Exc");
            tabSpec.SetContent(intent);
            tabSpec.SetIndicator("Exc (" + ExcCount + ")");
            tabHost.AddTab(tabSpec);


            intent = new Intent();
            intent.SetFlags(ActivityFlags.NewTask);
            intent.SetClass(this, typeof(RouteCheckoutRed));
            tabSpec = tabHost.NewTabSpec("Red");
            tabSpec.SetContent(intent);
            tabSpec.SetIndicator("Red (" + RedCount + ")");
            tabHost.AddTab(tabSpec);
    ViewGroup tabInidcator = (ViewGroup)tabHost.TabWidget.GetChildTabViewAt(0);

    ImageView img = (ImageView)tabInidcator.GetChildAt(0);

    TextView title = (TextView) tabInidcator.GetChildAt(1);
    title.Text = "xyz";

活动代码:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"   
        android:orientation="vertical"
        android:id="@+id/llcheckoutmiddle"
        android:layout_below="@id/llcheckouttop">
        <TabHost
            android:minWidth="25px"
            android:minHeight="25px"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/tabHostChkOut">
            <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:id="@+id/linearLayout1">
               <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="50dp" />
                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
            </LinearLayout>
        </TabHost>
    </LinearLayout>
            LocalActivityManager localActMgr = new LocalActivityManager(this, false);
            localActMgr.DispatchCreate(bundle);

            TabHost tabHost = FindViewById<TabHost>(Resource.Id.tabHostChkOut);
            tabHost.Setup(localActMgr);

            TabHost.TabSpec tabSpec = null;
            Intent intent = new Intent();

            intent = new Intent();
            intent.SetFlags(ActivityFlags.NewTask);
            intent.SetClass(this, typeof(RouteCheckoutExc));
            tabSpec = tabHost.NewTabSpec("Exc");
            tabSpec.SetContent(intent);
            tabSpec.SetIndicator("Exc (" + ExcCount + ")");
            tabHost.AddTab(tabSpec);


            intent = new Intent();
            intent.SetFlags(ActivityFlags.NewTask);
            intent.SetClass(this, typeof(RouteCheckoutRed));
            tabSpec = tabHost.NewTabSpec("Red");
            tabSpec.SetContent(intent);
            tabSpec.SetIndicator("Red (" + RedCount + ")");
            tabHost.AddTab(tabSpec);
    ViewGroup tabInidcator = (ViewGroup)tabHost.TabWidget.GetChildTabViewAt(0);

    ImageView img = (ImageView)tabInidcator.GetChildAt(0);

    TextView title = (TextView) tabInidcator.GetChildAt(1);
    title.Text = "xyz";
LocalActivityManager localActMgr=newlocalactivitymanager(此项为false);
localActMgr.DispatchCreate(bundle);
TabHost TabHost=findviewbyd(Resource.Id.tabHostChkOut);
tabHost.Setup(localActMgr);
TabHost.TabSpec TabSpec=null;
意图=新意图();
intent=新intent();
intent.SetFlags(ActivityFlags.NewTask);
intent.SetClass(这个,typeof(RouteCheckoutExc));
tabSpec=tabHost.NewTabSpec(“Exc”);
tabSpec.SetContent(意图);
tabSpec.SetIndicator(“Exc(“+ExcCount+”);
tabHost.AddTab(tabSpec);
intent=新intent();
intent.SetFlags(ActivityFlags.NewTask);
intent.SetClass(这个,typeof(RouteCheckoutRed));
tabSpec=tabHost.NewTabSpec(“红色”);
tabSpec.SetContent(意图);
tabSpec.SetIndicator(“红色(“+RedCount+”));
tabHost.AddTab(tabSpec);
我尝试了以下java代码。它不起作用

TextView txt = tabHost.GetChildAt(1).FindViewById(<Here I dont know what control I should give since there is no title defined>);
TextView txt=tabHost.GetChildAt(1.FindViewById();

在Xamarin.Android中,它应该是:

  TextView txt = tabHost.GetChildAt(0).FindViewById<TextView>(Resource.Id.title);

谢谢你的回答,杰克。但是没有一个适合我。第一行返回对象引用错误,第二行返回null。