Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

TabbedPage Bar change its color on Android

$
0
0

Hi guys!

I am doing an app that requires to set a TabbedPage (with 4 NavigationPage because the customer wants the tabs being visible the whole time) and everything is working fine on iOS, but, on Android, when I select a tab, the Bar (which on Android is an ActionBar) change its color to the default theme color.

I've been doing a lot of research (event customizing the theme's app) still getting this behavior . In fact, this only occurs on Samsung devices (I've tested it on Alcatel's phones and also Nexus 5 phones).

To be more specific, I've tried this combinations navigating between tabs:
* Tab 1 > Tab 2 = Bar still has the Color I desire
* Tab 1 > Tab 3 = Bar still has the Color I desire
* Tab 1 > Tab 4 = Bar still has the Color I desire
* Tab 1 > Tab 2/3/4 > Tab 3 = Bar change its color to the default's theme color until I come back to Tab 1

I have noticed that every third call to a page changes the color. I have tried to catch some error or something but nothing.

Additional: my TabbedPage calls a custom render to set the icons, even forcing the Tab.TabSelected event to set the background drawable to the action bar, nothing happens.

Somebody has or had this problem with Samsung devices before or maybe an annoying bug.

TabbedPage code

`

public class MainTabbedPage : TabbedPage
{
    public MainTabbedPage ()
    {
        Children.Add (new NavigationPage ( new HomePage () ) {
            BarBackgroundColor = Business.CorporateBlue,
            BarTextColor = Color.White,
            Icon = "ic_home.png"
        });

        Children.Add (new NavigationPage ( new FavoritesPages () ) {
            BarBackgroundColor = Business.CorporateBlue,
            BarTextColor = Color.White,
            Icon = "ic_favorites.png"
        });

        Children.Add (new NavigationPage ( new SearchPage () ) {
            BarBackgroundColor = Business.CorporateBlue,
            BackgroundColor = Business.CorporateBlue,
            BarTextColor = Color.White,
            Icon = "ic_search.png"
        });

        Children.Add (new NavigationPage ( new ContactPage () ) {
            BarBackgroundColor = Business.CorporateBlue,
            BarTextColor = Color.White,
            Icon = "ic_contact.png"
        });

    }

    protected override void OnAppearing ()
    {
        base.OnAppearing ();

    }

    protected override void OnCurrentPageChanged ()
    {
        base.OnCurrentPageChanged ();
        var current = (NavigationPage)this.CurrentPage;
        if (current.CurrentPage.GetType () == typeof(FavoritesPages)) {
            //Do something some day
        } else if (current.CurrentPage.GetType () == typeof(SearchPage)) {
            Device.BeginInvokeOnMainThread (() => ((SearchPage)current.CurrentPage).LoadPromotions ().ConfigureAwait (false));
        }


    }


}

`

CustomRenderer on Android Project
`

    public class CustomTabRenderer: TabbedRenderer 
        {
            protected override void OnElementChanged (ElementChangedEventArgs<TabbedPage> e)
            {
                base.OnElementChanged (e);
            }
            public override void OnWindowFocusChanged(bool hasWindowFocus)
            {   
                ActionBar actionBar = (Context as Activity).ActionBar;
                if (actionBar.TabCount > 0)
                {
                    foreach( Page page in Element.Children ) {

                        if (page.Icon == null)
                            continue;
                        int index = Element.Children.IndexOf ( page );
                        var tab = actionBar.GetTabAt( index );
                        tab.SetText (string.Empty);
                        tab.TabReselected += (object sender, ActionBar.TabEventArgs e) => 
                            page.Navigation.PopToRootAsync();
                        //Removing the .png because Android be crazy
                        tab.SetIcon (Resources.GetIdentifier (page.Icon.File.Replace(".png", ""), "drawable", Forms.Context.PackageName));

                    }
                }
                base.OnWindowFocusChanged(hasWindowFocus);
            }
        }

`

EDIT

Seems there somebody has reported this in https://bugzilla.xamarin.com/show_bug.cgi?id=22237

So for the moment I will show an icon in the bar meanwhile I figure out how to solve this "customer-friendly" way.

Regards


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>