Removing Tab Text on Android using FormsAppCompatActivity

I follow the @JamesMontemagno 's post about the implementation of Material in Android Apps using Xamarin.Forms 2.0 (So, I'm using FormsAppCompatActivity).

Everything went ok, until adding a TabbedPage to my app. My customer does not want a tittle in the tabs so I have to remove them. Before Xamarin.Forms 2.0, I was using ActionBar and I could remove the title easy using a custom render. But now seems to be so different (because now is using ToolBar).

Anyone has an idea how to achieve this without putting Title = "" on my code?

Thanks in advance

Best Answer

Answers

  • AdamMeaneyAdamMeaney ✭✭✭✭✭ USMember ✭✭✭✭✭
    edited December 2015

    This post seems to describe how to change Toolbar style. You could use this to set the text color to transparent for your tabs, and just leave them so one cannot see the text.

    EDIT I realized this was only for Toolbars. I cannot remember right now what the tab layout uses, but you should be able to theme it similarly.

  • JamesMontemagnoJamesMontemagno Xamurai USForum Administrator, Xamarin Team, Developer Group Leader Xamurai

    Do you want the title of your page or the title of each tab to be blank?

    You could just set this in your XAML:

    NavigationPage.HasNavigationBar="false" to hide it completely.

  • CarlosCamposSVCarlosCamposSV SVMember

    Actually each tab. How can I do this on code @JamesMontemagno ? I also tried with style but seems I have no luck.

  • CarlosCamposSVCarlosCamposSV SVMember

    I didn't want to do, but seems the easiest way to do it (without messing around with styles) but I prefer do this instead of using FormsApplicationActivity again :persevere:

    If later, I can find any other solution I will share it with you guys. Thanks for your time

  • CarlosCamposSVCarlosCamposSV SVMember

    @JamesMontemagno @AdamMeaney

    Seems that using app:tabTextColor attribute (in toolbar.axml) do almost the trick. I think using styling will be ok (I will read about this later). But, the selected tab shows again the color of the text (so the text is not removed).

    I'm thinking about somehow get the Activity of the TabbedPage and access the Tab or something

    I attached an screenshot of the app.

  • CarlosCamposSVCarlosCamposSV SVMember
    edited December 2015

    Seems that the simple way to achieve what I wanted I just set Title as "".

    So I did something like this:

    Title = Device.Idiom == TargetIdiom.Tablet ? "<The title here>" : string.Empty

    Because the customer wanted the title in the tab when using Tablet. And to set the Title in the NavigationBar I just added something like this (in a PhoneMasterDetailPage that I have created) which has a NavigationPage in the detail with a TabbedPage

    void CurrentPageChanged(object sender, EventArgs e)
            {
                var typePage = _tabsPage.CurrentPage.GetType();
                string title;
                if (typePage == typeof (AutorizationsPage))
                {
                    title = "Autorizaciones";
                }
                else if (typePage == typeof(RequestsPage))
                {
                    title = "Peticiones";
                }
                else if (typePage == typeof(QueriesPage))
                {
                    title = "Consultas";
                }
                else if (typePage == typeof (NotificationsPage))
                {
                    title = "Notificaciones";
                }
                else
                {
                    title = "Evolution";
                }
                _tabsPage.Title = title;
    
            }
    

    I don't know if this is a good practice but It does the trick. Just putting this as a reference. Thanks @JamesMontemagno and @AdamMeaney for your replies

Sign In or Register to comment.