Xamarin 单击当前选项卡时未调用OnTabChanged

Xamarin 单击当前选项卡时未调用OnTabChanged,xamarin,xamarin.android,mvvmcross,Xamarin,Xamarin.android,Mvvmcross,我使用TabHost和MvxTabsFragmentActivity用Xamarin.Android实现了一个选项卡式应用程序。 我想在第二次单击当前选项卡时刷新它 有没有从Android中选择类似OnTabReselected的方法 这就是我使用TabHost创建选项卡的方式: <TabHost android:id="@android:id/tabhost" android:layout_width="match_parent"

我使用TabHost和MvxTabsFragmentActivity用Xamarin.Android实现了一个选项卡式应用程序。 我想在第二次单击当前选项卡时刷新它

有没有从Android中选择类似OnTabReselected的方法

这就是我使用TabHost创建选项卡的方式:

    <TabHost android:id="@android:id/tabhost"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:background="@color/white">
      <LinearLayout android:orientation="vertical"
                    android:layout_width="match_parent" 
                    android:layout_height="match_parent">
        <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="7dp"
          android:background="@drawable/gradient_border_top"
          android:orientation="horizontal" />
        <TabWidget android:id="@android:id/tabs"
                   android:orientation="horizontal"
                   android:layout_width="match_parent" 
                   android:layout_height="56dp"
                   android:layout_weight="0"
                   android:background="@color/white" />
        <FrameLayout android:id="@android:id/tabcontent"
                     android:layout_width="0dp"
                     android:layout_height="0dp"
                     android:layout_weight="0" />
      </LinearLayout>
    </TabHost>

和主视图:

    [Activity(Theme = "@style/MyTheme", ScreenOrientation = ScreenOrientation.Portrait, WindowSoftInputMode = SoftInput.AdjustPan)]
    public class MainView : MvxTabsFragmentActivity
    {
        public MainView() : base(Resource.Layout.main_layout, Resource.Id.actualtabcontent)
        {
        }

        private static TabHost TabHost { get; set; }

        public override void OnTabChanged(string tag)
        {
            var pos = TabHost.CurrentTab;

            var tabView = TabHost.TabWidget.GetChildTabViewAt(pos);
            tabView.FindViewById<ImageView>(Resource.Id.tabImage)
                .SetColorFilter(new Color(ContextCompat.GetColor(Application.Context, Resource.Color.tabColorSelected)));
            tabView.FindViewById<TextView>(Resource.Id.tabTitle)
                .SetTextColor(new Color(ContextCompat.GetColor(Application.Context, Resource.Color.tabColorSelected)));

            for (var i = 0; i < TabHost.TabWidget.ChildCount; i++)
            {
                if (pos != i)
                {
                    var tabViewUnselected = TabHost.TabWidget.GetChildTabViewAt(i);
                    tabViewUnselected.FindViewById<ImageView>(Resource.Id.tabImage)
                        .SetColorFilter(new Color(ContextCompat.GetColor(Application.Context, Resource.Color.tabColor)));
                    tabViewUnselected.FindViewById<TextView>(Resource.Id.tabTitle)
                        .SetTextColor(new Color(ContextCompat.GetColor(Application.Context, Resource.Color.tabColor)));
                }
            }

            base.OnTabChanged(tag);
            }
        }

// This is where I add all 4 tabs
        protected override void AddTabs(Bundle args)
        {
            AddTab<TrackHomeView>(
                args,
                Mvx.IoCProvider.IoCConstruct<TrackHomeViewModel>(),
                CreateTabFor(((int)TabIdentifier.TrackTab).ToString(), Resource.Drawable.ic_track_icon, Strings.Track));

            AddTab<SendView>(
                args,
                Mvx.IoCProvider.IoCConstruct<SendViewModel>(),
                CreateTabFor(((int)TabIdentifier.SendTab).ToString(), Resource.Drawable.ic_send_icon, Strings.Send));

            if (MainViewModel.IsUserLoggedIn())
            {
                AddTab<ProfileView>(
                    args,
                    Mvx.IoCProvider.IoCConstruct<ProfileViewModel>(),
                    CreateTabFor(((int)TabIdentifier.ProfileTab).ToString(), Resource.Drawable.ic_profile_icon, Strings.Profile));
            }
            else
            {
                AddTab<CreateAccountView>(
                    args,
                    Mvx.IoCProvider.IoCConstruct<CreateAccountViewModel>(),
                    CreateTabFor(((int)TabIdentifier.ProfileTab).ToString(), Resource.Drawable.ic_profile_icon, Strings.Profile));
            }

            AddTab<MoreView>(
                args,
                Mvx.IoCProvider.IoCConstruct<MoreViewModel>(),
                CreateTabFor(((int)TabIdentifier.MoreTab).ToString(), Resource.Drawable.ic_more_icon, Strings.More));
        }

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            TabHost = FindViewById<TabHost>(global::Android.Resource.Id.TabHost);
            TabHost.TabWidget.SetDividerDrawable(null);
            TabHost.Setup();

        }
[活动(主题=“@style/MyTheme”,ScreenOrientation=ScreenOrientation.肖像,WindowsOfInputMode=SoftInput.AdjustPan)]
公共类主视图:MvxTabsFragmentActivity
{
public MainView():基本(Resource.Layout.main\u布局,Resource.Id.actualtabcontent)
{
}
私有静态TabHost TabHost{get;set;}
公共覆盖无效OnTabChanged(字符串标记)
{
var pos=TabHost.CurrentTab;
var tabView=TabHost.TabWidget.GetChildTabViewAt(pos);
tabView.findviewbyd(Resource.Id.tabImage)
.SetColorFilter(新颜色(ContextCompat.GetColor(Application.Context,Resource.Color.tabColorSelected));
tabView.findviewbyd(Resource.Id.tabTitle)
.SetTextColor(新颜色(ContextCompat.GetColor(Application.Context,Resource.Color.tabColorSelected));
对于(var i=0;i
我只添加了相关代码。
选项卡是使用TabHost创建的,活动是从MvxTabsFragmentActivity继承的。

您可以继承TabHost的
MvxTabsFragmentActivity
中的
ActionBar.ITabListener
界面,然后您可以获得所需的事件

public class MainActivity : MvxTabsFragmentActivity, ActionBar.ITabListener
{
 public void OnTabReselected(ActionBar.Tab tab, FragmentTransaction ft)
{
    // Optionally refresh/update the displayed tab.
    Log.Debug(Tag, "The tab {0} was re-selected.", tab.Text);
}

public void OnTabSelected(ActionBar.Tab tab, FragmentTransaction ft)
{
    // Display the fragment the user should see
    Log.Debug(Tag, "The tab {0} has been selected.", tab.Text);
}

public void OnTabUnselected(ActionBar.Tab tab, FragmentTransaction ft)
{
    // Save any state in the displayed fragment.
    Log.Debug(Tag, "The tab {0} as been unselected.", tab.Text);
}
...

不管我以前说过什么,今天我学到了一些我认为不可能的新东西。试试这个,我使用了TabHost,因为MvxTabsFragmentActivity使用的是TabHost,而不是TabLayout。没有一个方法被命中。但是我可以看看你的代码吗?如果没有,请查看此链接。您是否查看了上面的链接?此外,您似乎没有使用我在回答中建议的内容。我删除了您建议我使用的内容,因为我只想添加我正在使用的代码。我建议您尝试复制链接中的代码