简体   繁体   English

单击两次相同的选项卡文本/图标时如何使选项卡式页面导航?

[英]how to make the tabbed page navigate when clicked on the same tab text/icon twice?

So i have a tabbed page, and there are several tabs associated with it所以我有一个标签页,并且有几个与之关联的标签在此处输入图像描述

on the first tab i have a list, in which if i click a tile, lets say tile1, then i open up another page keeping the tabs intact, but what i want to is when i click the tab option1 again, then it should go to the main list, which is not happening any insight would be really helpful Clicking on "tile1", i do在第一个选项卡上我有一个列表,如果我单击一个图块,假设为 tile1,然后我打开另一个页面保持标签不变,但我想要的是当我再次单击选项卡选项 1 时,它应该是 go到主列表,这没有发生任何见解都会非常有帮助点击“tile1”,我愿意

await Navigation.PushAsync(new SubCategoryView());

which i assume is the correct way, and ironically enough intended behaviour works in iOS but not on Android我认为这是正确的方法,具有讽刺意味的是,预期的行为在 iOS 中有效,但在 Android 中无效

If you want to return to the root page when select the same tabbed, you can use Custom Renderer如果想在 select 同分页时返回根页面,可以使用Custom Renderer

in Android在 Android


using Android.Content;

using Android.Support.Design.Widget;
using xxx;
using xxx.Droid;

using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms.Platform.Android.AppCompat;

[assembly: ExportRenderer(typeof(TabbedPage), typeof(MyTabbedRenderer))]
namespace xxx.Droid
{
    public class MyTabbedRenderer : TabbedPageRenderer, TabLayout.IOnTabSelectedListener
    {

        public MyTabbedRenderer(Context context) : base(context)
        {

        }

        private TabbedPage tabbed;
        protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                tabbed = (TabbedPage)e.NewElement;
            }
            else
            {
                tabbed = (TabbedPage)e.OldElement;
            }

        }
        async void TabLayout.IOnTabSelectedListener.OnTabReselected(TabLayout.Tab tab)
        {
            await tabbed.CurrentPage.Navigation.PopToRootAsync();
        }

    }

   
}

in iOS在 iOS

using UIKit;
using System;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using xxx;
using xxx.iOS;

[assembly: ExportRenderer(typeof(TabbedPage), typeof(MyTabbedRenderer))]
namespace xxx.iOS
{
    public class MyTabbedRenderer : TabbedRenderer
    {
        private TabbedPage tabbed;
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                tabbed = (TabbedPage)e.NewElement;
            }
            else
            {
                tabbed = (TabbedPage)e.OldElement;
            }

            try
            {
                var tabbarController = (UITabBarController)this.ViewController;
                if (null != tabbarController)
                {
                    tabbarController.ViewControllerSelected += OnTabbarControllerItemSelected;
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }

        private async void OnTabbarControllerItemSelected(object sender, UITabBarSelectionEventArgs eventArgs)
        {
            if (tabbed?.CurrentPage?.Navigation != null && tabbed.CurrentPage.Navigation.NavigationStack.Count > 0)
            {
                await tabbed.CurrentPage.Navigation.PopToRootAsync();
            }

        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改选项卡式页面图标的颜色? - How to change tabbed page icon color? 在标签页标签内的页面之间导航,但不会丢失标签页标签 - Navigate between pages inside tabbed page tab, but without losing the tab page tabs 如何使Android中的图标与文字大小相同? - How to make icon the same size as text in Android? 当单击后退图标而不是Android中完整的工具栏时,如何导航到上一个活动? - How to navigate to previous activity when back icon is clicked instead of the complete toolbar in Android? 单击时如何更改操作栏图标 - How to make action bar icon change when clicked 如何使用图标下方的文字制作Actionbar标签菜单? - How to make actionbar tab menu with text below the icon? 单击打开幻灯片菜单时如何在福尔摩斯动作栏中制作图标 - How to make icon in sherlock actionbar when clicked open slidemenu 在选项卡式活动中设置带有文本的图标 - Set Icon with Text in a Tabbed Activity 底部导航图标仅在单击两次时更改颜色? - Bottom navigation icon only changing color when clicked twice? 单击图标时 BottomNavigationBarItem 打开相应的页面 - BottomNavigationBarItem open respective page when clicked on the Icon
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM