title: Xamarin Forms Android Custom TabbedPage ActionBar is returning null
body: <p>I am using <code>custom TabbedPage</code> in my project for showing a <code>badges(count)</code> in <code>Tab bar</code>. I am using the below code for showing a <code>custom tab bar</code> but it is  always returning <code>null</code> value in <code>CustomTabbedPageRenderer.cs</code> class <code>OnWindowVisibilityChanged</code> method's <code>activity.ActionBar</code>. I have tried the many workaround like changing the <code>Theme</code> as <code>Theme.AppCompat.Light.DarkActionBar</code> and added the below line in <code>Window.RequestFeature(WindowFeatures.ActionBar);</code> <strong>MainActivity.cs</strong> , but unfortunately these didn't help me. </p>
  
  <p><strong>MainActivity.cs</strong></p>
  
  <pre><code>  namespace Bakery.Droid
      {
          [Activity(Label = "Bakery.Droid", Icon = "@mipmap/icon_launcher", Theme = "@style/MyTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait)]
          public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
          {
                  protected override void OnCreate(Bundle bundle)
                  {
  
                      base.OnCreate(bundle);
  
                      global::Xamarin.Forms.Forms.Init(this, bundle);         
  
                      LoadApplication(new App());
                  }
  
  
              }
  
          }
  </code></pre>
  
  <p><strong>Home.cs</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using Xamarin.Forms;
  
  namespace Bakery
  {
      public class Home : CustomTabPage
      {
          public Home()
          {
  
              NavigationPage.SetHasNavigationBar(this, false);
  
              var burger = new NavigationPage(new Burger());
              burger.Icon = "burger.png";
              burger.Title = "Burger";
  
              var sandwich = new NavigationPage(new Sandwich());
              sandwich.Icon = "sandwich.png";
              sandwich.Title = "Sandwich";
  
              var pizza = new NavigationPage(new Pizza());
              pizza.Icon = "pizza.png";
              pizza.Title = "Pizza";
  
  
              var roll = new NavigationPage(new Roll());
              roll.Icon = "roll.png";
              roll.Title = "Roll";
  
              //adding childrens into the tab
              Children.Clear();
              Children.Add(burger);
              Children.Add(sandwich);
              Children.Add(pizza);
              Children.Add(roll);
          }
  
          protected override void OnAppearing()
          {
              base.OnAppearing();     
          }
      }
  }
  </code></pre>
  
  <p><strong>CustomTabPage.cs</strong></p>
  
  <pre><code>using System;
  using Xamarin.Forms;
  
  namespace Bakery
  {
      public class CustomTabPage : TabbedPage
      {
  
      }
  }
  </code></pre>
  
  <p><strong>styles.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;resources&gt;
      &lt;style name="MyTheme" parent="MyTheme.Base"&gt;
      &lt;/style&gt;
  
      &lt;style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"&gt;
  
          &lt;item name="windowNoTitle"&gt;true&lt;/item&gt;
  
          &lt;item name="windowActionBar"&gt;true&lt;/item&gt;        
  
          &lt;item name="windowActionModeOverlay"&gt;true&lt;/item&gt;        
  
  
      &lt;/style&gt;
  
  &lt;/resources&gt;
  </code></pre>
  
  <p><strong>CustomTabbedPageRenderer.cs</strong></p>
  
  <pre><code> [assembly: ExportRenderer(typeof(TabbedPage), typeof(CustomTabbedPageRenderer))]
      namespace Bakery.Droid
      {
          public class CustomTabbedPageRenderer : TabbedRenderer
          {
              Activity activity;
              List&lt;string&gt; filenames;
  
              protected override void OnElementChanged(ElementChangedEventArgs&lt;TabbedPage&gt; e)
              {
                  base.OnElementChanged(e);
                  filenames = e.NewElement.Children.Select(t =&gt; t.Icon.File).ToList();
              }
  
              protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
              {
                  base.OnElementPropertyChanged(sender, e);
                  activity = this.Context as Activity;
              }
  
              protected override void OnWindowVisibilityChanged(Android.Views.ViewStates visibility)
              {
                  try
                  {
                      base.OnWindowVisibilityChanged(visibility);
                      var actionBar = activity.ActionBar;
                      var colorDrawable = new ColorDrawable(Android.Graphics.Color.Yellow);
                      actionBar.SetStackedBackgroundDrawable(colorDrawable);
                      System.Diagnostics.Debug.WriteLine("Onwindow visible");
                      ActionBarTabsSetup(actionBar);
                  }
                  catch (Exception Exception)
                  {
                      System.Diagnostics.Debug.WriteLine("Exception: " + Exception.ToString());
                  }
              }
  
              void ActionBarTabsSetup(ActionBar actionBar)
              {
                  for (var i = 0; i &lt; actionBar.NavigationItemCount; ++i)
                  {
                      var tab = actionBar.GetTabAt(i);
                      var id = GetImageFromFilename(i);
                      if (id != 0)
                          TabSetup(tab, id);
                  }
              }
  
              void TabSetup(ActionBar.Tab tab, int resID)
              {
                  var relLay = new Android.Widget.RelativeLayout(activity)
                  {
                      LayoutParameters = new LayoutParams(LayoutParams.WrapContent, 180)
  
                  };
  
                  var linLay = new LinearLayout(activity)
                  {
                      LayoutParameters = new LayoutParams(LayoutParams.WrapContent, 180),
                      Orientation = Orientation.Vertical,
                  };
                  linLay.SetHorizontalGravity(Android.Views.GravityFlags.Center);
                  var imageView = new ImageView(activity);
                  imageView.SetImageResource(resID);
                  imageView.SetPadding(-35, 4, -35, 0);
                  imageView.SetMinimumWidth(60);
  
                  var textView = new TextView(activity)
                  {
                      Text = tab.Text
                  };
  
  
                  linLay.AddView(imageView);
                  linLay.AddView(textView);       
  
                  relLay.AddView(linLay);
  
                  var badgeView = new TextView(activity)
                  {
                      Text = "2"
                  };
  
                  var badgeImageView = new ImageView(activity);
                  badgeImageView.SetImageResource(Resource.Drawable.red);
                  badgeImageView.SetMinimumWidth(5);
                  badgeImageView.SetMinimumHeight(5);
                  badgeImageView.SetPadding(77, 5, 0, 0);
                  badgeView.SetPadding(85, 0, 0, 0);
  
                  relLay.AddView(badgeImageView);
                  relLay.AddView(badgeView);
                  tab.SetCustomView(relLay);
              }
  
              int GetImageFromFilename(int n)
              {
                  var filename = filenames[n].Split('.');
                  var id = Resources.GetIdentifier(filename[0], "drawable", activity.PackageName);
                  return id;
              }
          }
      }
  </code></pre>