public override void SetContentView(int layoutResID)
 {
     if (drawerLayout != null)
     {
         LayoutInflater         inflater = (LayoutInflater)GetSystemService(LayoutInflaterService);
         ViewGroup.LayoutParams lp       = new ViewGroup.LayoutParams(
             ViewGroup.LayoutParams.MatchParent,
             ViewGroup.LayoutParams.MatchParent);
         View stubView = inflater.Inflate(layoutResID, drawerLayout, false);
         drawerLayout.AddView(stubView, lp);
     }
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create the UI
            var v = OnCreateMainView(savedInstanceState);

            _drawer = new DrawerLayout(this);
            _drawer.AddView(v,
                            new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent));
            AddContentView(_drawer,
                           new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent));

            // prep drawer if needed
            var navigationView = new NavigationView(this);
            var menu           = navigationView.Menu;

            if (OnPrepareSideMenu(menu))
            {
                navigationView.SetNavigationItemSelectedListener(this);
                _drawer.AddView(navigationView,
                                new DrawerLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent,
                                                              ViewGroup.LayoutParams.MatchParent, (int)GravityFlags.Start));

                // set the header
                var header = OnCreateMenuHeaderView(LayoutInflater.From(this));
                if (header != null)
                {
                    navigationView.AddHeaderView(header);
                }

                // fetch the theme...
                var a = new TypedValue();
                Theme.ResolveAttribute(global::Android.Resource.Attribute.ColorBackground, a, true);
                if (a.Type >= DataType.FirstColorInt && a.Type <= DataType.LastColorInt)
                {
                    navigationView.SetBackgroundColor(new global::Android.Graphics.Color(a.Data));
                }

                // notify when drawer opens / closes
                _drawerToggle = OnCreateDrawerToggle(this, _drawer);
                _drawer.AddDrawerListener(_drawerToggle);

                SupportActionBar.SetDisplayHomeAsUpEnabled(true);
                SupportActionBar.SetHomeButtonEnabled(true);
            }
        }
Exemplo n.º 3
0
        void LayoutSideBySide()
        {
            var flyoutView = _flyoutView;

            if (MauiContext == null || _navigationRoot == null || flyoutView == null)
            {
                return;
            }

            if (_sideBySideView == null)
            {
                _sideBySideView = new LinearLayoutCompat(Context)
                {
                    Orientation      = LinearLayoutCompat.Horizontal,
                    LayoutParameters = new DrawerLayout.LayoutParams(
                        DrawerLayout.LayoutParams.MatchParent,
                        DrawerLayout.LayoutParams.MatchParent)
                };
            }

            if (_navigationRoot.Parent != _sideBySideView)
            {
                _navigationRoot.RemoveFromParent();

                var layoutParameters =
                    new LinearLayoutCompat.LayoutParams(
                        LinearLayoutCompat.LayoutParams.MatchParent,
                        LinearLayoutCompat.LayoutParams.MatchParent,
                        1);

                _sideBySideView.AddView(_navigationRoot, layoutParameters);
                UpdateDetailsFragmentView();
            }

            if (flyoutView.Parent != _sideBySideView)
            {
                // When the Flyout is acting as a flyout Android will set the Visibilty to GONE when it's off screen
                // This makes sure it's visible
                flyoutView.Visibility = ViewStates.Visible;
                flyoutView.RemoveFromParent();
                var layoutParameters =
                    new LinearLayoutCompat.LayoutParams(
                        (int)FlyoutWidth,
                        LinearLayoutCompat.LayoutParams.MatchParent,
                        0);

                _sideBySideView.AddView(flyoutView, 0, layoutParameters);
            }

            if (_sideBySideView.Parent != PlatformView)
            {
                DrawerLayout.AddView(_sideBySideView);
            }

            if (VirtualView is IToolbarElement te && te.Toolbar?.Handler is ToolbarHandler th)
            {
                th.SetupWithDrawerLayout(null);
            }
        }
Exemplo n.º 4
0
        void LayoutAsFlyout()
        {
            var flyoutView = _flyoutView;

            if (MauiContext == null || _navigationRoot == null || flyoutView == null)
            {
                return;
            }

            _sideBySideView?.RemoveAllViews();
            _sideBySideView?.RemoveFromParent();

            if (_navigationRoot.Parent != PlatformView)
            {
                _navigationRoot.RemoveFromParent();

                var layoutParameters =
                    new LinearLayoutCompat.LayoutParams(
                        LinearLayoutCompat.LayoutParams.MatchParent,
                        LinearLayoutCompat.LayoutParams.MatchParent);

                DrawerLayout.AddView(_navigationRoot, 0, layoutParameters);
            }

            UpdateDetailsFragmentView();

            if (flyoutView.Parent != PlatformView)
            {
                flyoutView.RemoveFromParent();

                var layoutParameters =
                    new DrawerLayout.LayoutParams(
                        (int)FlyoutWidth,
                        DrawerLayout.LayoutParams.MatchParent,
                        (int)GravityFlags.Start);

                // Flyout has to get added after the content otherwise clicking anywhere
                // on the flyout will cause it to close and gesture
                // recognizers inside the flyout won't fire
                DrawerLayout.AddView(flyoutView, layoutParameters);
            }

            DrawerLayout.CloseDrawer(flyoutView);

            if (VirtualView is IToolbarElement te && te.Toolbar?.Handler is ToolbarHandler th)
            {
                th.SetupWithDrawerLayout(DrawerLayout);
            }
        }