Skip to content

Instantly share code, notes, and snippets.

@programmation
Created May 4, 2015 04:21
Show Gist options
  • Save programmation/f210ae8551e73cbbc64b to your computer and use it in GitHub Desktop.
Save programmation/f210ae8551e73cbbc64b to your computer and use it in GitHub Desktop.
Xamarin Forms Android Tab Bar with Icons
// https://forums.xamarin.com/discussion/comment/119662/#Comment_119662
public class IconTabbedRenderer : TabbedRenderer
{
protected override void DispatchDraw(
global::Android.Graphics.Canvas canvas)
{
base.DispatchDraw(canvas);
SetTabIcons();
}
private void SetTabIcons()
{
var element = this.Element;
if (null == element)
{
return;
}
Activity activity = this.Context as Activity;
if ((null != activity)
&& (null != activity.ActionBar)
&& (activity.ActionBar.TabCount > 0))
{
for (int i = 0; i < element.Children.Count; i += 1)
{
var tab = activity.ActionBar.GetTabAt(i);
var page = element.Children[i];
if ((null != tab) && (null != page) && (null != page.Icon))
{
int resourceId = this.Context.Resources.GetIdentifier(
page.Icon.File, "drawable", this.Context.PackageName);
tab.SetIcon(resourceId);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment