title: Xamarin Android BottomBarBadge doesn't properly display counts of 100+
body: <p>When I try to display a count higher than 99 in the <code>BottomBarBadge</code>, it won't be displayed correctly because there is not enough space in the Badge. </p>
  
  <p>This screenshot shows a badge which actually contains a count of 110, but it looks like "11" because the "0" is cut off by the small badge:</p>
  
  <p><a href="https://i.stack.imgur.com/gHXA3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gHXA3.png" alt="enter image description here"></a></p>
  
  <p>The problem is that when the count changes, I just set the new <code>badge.Count</code> like this:</p>
  
  <pre><code>badge.Count = int.Parse(text);
  </code></pre>
  
  <p>At this point, I expect the badge to automatically render it's new width to fit the new count if it needs a new height (e.g. changed from 99 to 100 or the other way around). But that doesn't seem to happen.</p>
  
  <p>Is there a method or some other thing I am missing which updates the badge's width? </p>
  
  <p>I expect the badge to stretch a bit in it's width if needed, like in WhatsApp:</p>
  
  <p><a href="https://i.stack.imgur.com/YR1Ow.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YR1Ow.png" alt="enter image description here"></a></p>
  
  <p>I am using the 3rd Party BottomNavigationBar by pocheshire: <a href="https://github.com/pocheshire/BottomNavigationBar" rel="nofollow noreferrer">https://github.com/pocheshire/BottomNavigationBar</a></p>
  
  <hr>
  
  <h2>EDIT:</h2>
  
  <p>Using <a href="https://stackoverflow.com/questions/50675807/xamarin-android-bottombarbadge-doesnt-properly-display-counts-of-100/50676666#50676666">Sushi Hangover's answer</a> did work, but it broke something else. When I tap on a tab which contains a badge, the app will crash in a <code>NullReferenceException</code>:</p>
  
  <pre><code>System.NullReferenceException: Object reference not set to an instance of an object.
    at BottomNavigationBar.BottomBar.HandleClick (Android.Views.View v) [0x00010] in &lt;f60603cf39c84bebb4c6ba69e7e8bb64&gt;:0 
    at BottomNavigationBar.BottomBar+&lt;MakeBadgeForTabAt&gt;c__AnonStorey1.&lt;&gt;m__0 () [0x00011] in &lt;f60603cf39c84bebb4c6ba69e7e8bb64&gt;:0 
    at BottomNavigationBar.Listeners.OnTabClickListener.OnClick (Android.Views.View v) [0x0000d] in &lt;f60603cf39c84bebb4c6ba69e7e8bb64&gt;:0 
    at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v) [0x0000f] in &lt;263adecfa58f4c449f1ff56156d886fd&gt;:0 
    at (wrapper dynamic-method) System.Object.30ced559-6971-4697-bb8d-82a961a4b1e9(intptr,intptr,intptr)
  </code></pre>
  
  <p>I could not find a mistake in the Custom Renderer, I did set breakpoints at every line of code which calls <code>MakeBadgeForTabAt()</code>, but it didn't execute this code before the Exception occured.</p>
  
  <p>This is the code which seems to causes the exception:</p>
  
  <pre><code>protected virtual void OnTabbedPagePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  {
      var page = sender as Page;
      if (page == null)
          return;
  
      if (e.PropertyName == TabBadge.BadgeTextProperty.PropertyName)
      {
          if (CheckValidTabIndex(page, out int tabIndex))
          {
              var element = Element.Children[tabIndex];
              UpdateTabBadgeText(BadgeViews[element], page);
          }
          return;
      }
  }
  
  private void UpdateTabBadgeText(BottomBarBadge badge, Element element)
  {
      var text = TabBadge.GetBadgeText(element);
      if (!String.IsNullOrEmpty(text))
      {
          try
          {
              // This does not cause an exception, but doesn't update the badge's size:
              // badge.Count = int.Parse(text);
  
              // This causes NullReferenceException when taping the tab:
              var index = Element.Children.IndexOf((Page)element);
              _bottomBar.RemoveBadgeAt(index);
              _bottomBar.MakeBadgeForTabAt(index, "#FF0000", int.Parse(text));
          }
          catch (Exception)
          {
              // exception handling
          }
      }
      if (badge.Count == 0)
      {
          badge.Hide(false);
      }
      else
      {
          badge.Show(false);
      }
  }
  </code></pre>