Exemplo n.º 1
0
        void AddToolbarItems()
        {
#if __ANDROID__
            var actionButton = new FloatingActionButton(Forms.Context);

            actionButton.SetImageResource(XFDraw.Droid.Resource.Drawable.trash);
            actionButton.Click += (s, e) => OnClearClicked();

            var actionButtonFrame = new FrameLayout(Forms.Context);
            actionButtonFrame.SetClipToPadding(false);
            actionButtonFrame.SetPadding(0, 0, 50, 50);
            actionButtonFrame.AddView(actionButton);

            var actionButtonFrameView = actionButtonFrame.ToView();
            actionButtonFrameView.HorizontalOptions = LayoutOptions.End;
            actionButtonFrameView.VerticalOptions   = LayoutOptions.End;


            mainLayout.Children.Add(actionButtonFrameView, 0, 1);
#else
            clearCommand = new Command(OnClearClicked, () => { return(IsCanvasDirty); });

            var trash = new ToolbarItem()
            {
                Text    = "Clear",
                Icon    = "trash.png",
                Command = clearCommand
            };

            ToolbarItems.Add(trash);
#endif
        }
Exemplo n.º 2
0
        public MainPage()
        {
            InitializeComponent();



            sketchView.SketchUpdated += OnSketchUpdate;

            clearCommand = new Command(OnClearClicked, () => { return(isCanvasDirty); });

            var trash = new ToolbarItem()
            {
                Text    = "Clear",
                Icon    = "trash.png",
                Command = clearCommand,
            };

            trash.Clicked += (o, s) => OnClearClicked();

            ToolbarItems.Add(trash);

#if __ANDROID__
            var actionButton = new FloatingActionButton(Forms.Context);
            actionButton.SetImageResource(XFDraw.Droid.Resource.Drawable.pencil);
            actionButton.Click += (s, e) =>
            {
                OnColorClicked();
                actionButton.BackgroundTintList = Android.Content.Res.ColorStateList.ValueOf(sketchView.InkColor.ToAndroid());
            };

            var actionButtonFrame = new FrameLayout(Forms.Context);
            actionButtonFrame.SetClipToPadding(false);
            actionButtonFrame.SetPadding(0, 0, 50, 50);
            actionButtonFrame.AddView(actionButton);

            var actionButtonFrameView = actionButtonFrame.ToView();
            actionButtonFrameView.HorizontalOptions = LayoutOptions.End;
            actionButtonFrameView.VerticalOptions   = LayoutOptions.End;

            mainLayout.Children.Add(actionButtonFrameView);
#else
            ToolbarItems.Add(new ToolbarItem("New Color", "pencil.png", OnColorClicked));
#endif
        }
Exemplo n.º 3
0
        public Xamarin.Forms.View CreateFloatingActionButton(Action tappedCallback)
        {
            //Get native control
            var actionButton = new FloatingActionButton(MainActivity.Activity);


            //Set Button background and icon
            actionButton.BackgroundTintList = ColorStateList.ValueOf(global::Android.Graphics.Color.ParseColor("#0098E9"));
            actionButton.SetImageResource(Resource.Drawable.icon);


            //Fix Button margin (this will add a shadow to button)
            float d      = MainActivity.Activity.Resources.DisplayMetrics.Density;
            var   margin = (int)(16 * d); // margin in pixels (margin * dpi)
            var   lp     = new FrameLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent);

            lp.Gravity      = GravityFlags.CenterVertical | GravityFlags.CenterHorizontal;
            lp.LeftMargin   = margin;
            lp.TopMargin    = margin;
            lp.BottomMargin = margin;
            lp.RightMargin  = margin;
            actionButton.LayoutParameters = lp;

            //When Native control is tapped , we will pass the call to Xam.Forms through the Action received
            actionButton.Click += (s, a) => { tappedCallback(); };

            //set the position of button bottom-right corner of container
            var actionButtonFrame = new FrameLayout(MainActivity.Activity);

            actionButtonFrame.SetClipToPadding(true);
            actionButtonFrame.SetPadding(0, 0, 50, 50);
            actionButtonFrame.AddView(actionButton);

            //Convert native control  to Xam.Forms View  and return it to Xam.Forms
            var actionButtonFrameView = actionButtonFrame.ToView();

            actionButtonFrameView.HorizontalOptions = LayoutOptions.End;
            actionButtonFrameView.VerticalOptions   = LayoutOptions.End;

            return(actionButtonFrameView);
        }