Как обновить индикатор TabHost в Android Xamarin - PullRequest
0 голосов
/ 01 ноября 2019

Мне нужно динамически менять вкладку Индикатор. Я мог бы найти ответы в 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);

Я попробовалследующий код Java. Это не сработало.

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

1 Ответ

1 голос
/ 04 ноября 2019

В Xamarin.Android это должно быть:

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

Или

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

Чтобы обновить индикатор TabHost в Android Xamarin:

    ViewGroup tabInidcator = (ViewGroup)tabHost.TabWidget.GetChildTabViewAt(0);

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

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