Collapsible Toolbar in Forms application?

caseyryancaseyryan Member ✭✭
edited March 28 in Xamarin.Forms

Hi!
I've googled a lot of different resources and basicaly found no answer to my question which is: is it possible to create this

using Xamarin Forms? I can achieve changing the color of the ToolBar to transparent but the problem is that the page's content is clipped by the toolbar and so I can't get the same effect. Right now the only solution I see is to create my own "fake" system of Toolbars and Tabbars with this functionality but it won't be native so it's not preffered

Answers

  • caseyryancaseyryan Member ✭✭

    any ideas?

  • yelinzhyelinzh Member, Xamarin Team Xamurai
    edited April 3

    Try to custom a layout in Android and render the layout in CustomRenderer. Add the view to renderer class.

    [assembly:ExportRenderer(typeof(Custom_View),typeof(View_renderer))]
    namespace App3.Droid
    {
        class View_renderer : ViewRenderer
        {
            Context context;
            Android.Views.View view;
            public View_renderer(Context context) : base(context)
            {
                this.context = context;
            }
    
            protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.View> e)
            {
                base.OnElementChanged(e);
                addView();
                AddView(view);
            }
    
            private void addView()
            {
                view = LayoutInflater.From(context).Inflate(Resource.Layout.layout_, null);
            }
    
            protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
            {
                base.OnLayout(changed, left, top, right, bottom);
                var width = MeasureSpec.MakeMeasureSpec(right - left, MeasureSpecMode.Exactly);
                var height = MeasureSpec.MakeMeasureSpec(bottom - top, MeasureSpecMode.Exactly);
                view.Measure(width,height);
                view.Layout(0, 0, right - left, bottom - top);
            }
    
        }
    }
    
  • yelinzhyelinzh Member, Xamarin Team Xamurai

    @caseyryan I added the OnLayout method to update the code and it has been deployed successfully.

  • caseyryancaseyryan Member ✭✭
    Hi @yelinzh! I haven't tested it yet, but it looks like a great idea. Thanks! I'll give it a try as soon as I can
  • yelinzhyelinzh Member, Xamarin Team Xamurai

    Have you tried? What's the result?

Sign In or Register to comment.