summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/Renderers/ToolbarRenderer.cs
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-03-22 13:02:25 -0700
committerJason Smith <jason.smith@xamarin.com>2016-03-22 16:13:41 -0700
commit17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch)
treeb5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Platform.Android/Renderers/ToolbarRenderer.cs
downloadxamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip
Initial import
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Renderers/ToolbarRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/ToolbarRenderer.cs65
1 files changed, 65 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/ToolbarRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/ToolbarRenderer.cs
new file mode 100644
index 00000000..f40b75f3
--- /dev/null
+++ b/Xamarin.Forms.Platform.Android/Renderers/ToolbarRenderer.cs
@@ -0,0 +1,65 @@
+using Android.Widget;
+using AScrollView = Android.Widget.ScrollView;
+using AButton = Android.Widget.Button;
+using AView = Android.Views.View;
+
+namespace Xamarin.Forms.Platform.Android
+{
+ public class ToolbarRenderer : ViewRenderer
+ {
+ public ToolbarRenderer()
+ {
+ AutoPackage = false;
+ }
+
+ protected override void OnElementChanged(ElementChangedEventArgs<View> e)
+ {
+ base.OnElementChanged(e);
+
+ if (e.OldElement == null)
+ {
+ var layout = new LinearLayout(Context);
+ layout.SetBackgroundColor(new Color(0.2, 0.2, 0.2, 0.5).ToAndroid());
+
+ layout.Orientation = Orientation.Horizontal;
+
+ SetNativeControl(layout);
+ }
+ else
+ {
+ var oldToolbar = (Toolbar)e.OldElement;
+ oldToolbar.ItemAdded -= OnToolbarItemsChanged;
+ oldToolbar.ItemRemoved -= OnToolbarItemsChanged;
+ }
+
+ UpdateChildren();
+
+ var toolbar = (Toolbar)e.NewElement;
+ toolbar.ItemAdded += OnToolbarItemsChanged;
+ toolbar.ItemRemoved += OnToolbarItemsChanged;
+ }
+
+ void OnToolbarItemsChanged(object sender, ToolbarItemEventArgs e)
+ {
+ UpdateChildren();
+ }
+
+ void UpdateChildren()
+ {
+ RemoveAllViews();
+
+ foreach (ToolbarItem child in ((Toolbar)Element).Items)
+ {
+ AView view = null;
+
+ if (!string.IsNullOrEmpty(child.Icon))
+ view = new ToolbarImageButton(Context, child);
+ else
+ view = new AButton(Context);
+
+ using(var param = new LinearLayout.LayoutParams(LayoutParams.WrapContent, (int)Context.ToPixels(48), 1))
+ ((LinearLayout)Control).AddView(view, param);
+ }
+ }
+ }
+} \ No newline at end of file