protected override void OnElementChanged(ElementChangedEventArgs <NavigationPage> e) { base.OnElementChanged(e); if (e.OldElement != null) { if (_toolbar != null) { _toolbar.RemoveFromParent(); } } if (e.NewElement != null) { _toolbar = (Toolbar)GetChildAt(0); var getNavBarHeight = typeof(NavigationPageRenderer).GetMethod("ActionBarHeight", BindingFlags.Instance | BindingFlags.NonPublic); _barHeight = (int)getNavBarHeight.Invoke(this, new object[] { }); _appBarLayout = (Context as FormsAppCompatActivity).FindViewById <AppBarLayout>(Resource.Id.coordinatorAppBar); _toolbar.RemoveFromParent(); using (var toolbarParams = new AppBarLayout.LayoutParams(LayoutParams.MatchParent, _barHeight)) { toolbarParams.ScrollFlags = AppBarLayout.LayoutParams.ScrollFlagScroll | AppBarLayout.LayoutParams.ScrollFlagEnterAlways; _appBarLayout.AddView(_toolbar, toolbarParams); } } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); var info = FamiStudioForm.Instance != null ? FamiStudioForm.Instance.ActiveDialog as PropertyDialogActivityInfo : null; if (savedInstanceState != null || info == null) { Finish(); return; } dlg = info.Dialog; dlg.CloseRequested += Dlg_CloseRequested; var appBarLayoutParams = new AppBarLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, DroidUtils.GetSizeAttributeInPixel(this, Android.Resource.Attribute.ActionBarSize)); appBarLayoutParams.ScrollFlags = 0; toolbar = new AndroidX.AppCompat.Widget.Toolbar(new ContextThemeWrapper(this, Resource.Style.ToolbarTheme)); toolbar.LayoutParameters = appBarLayoutParams; toolbar.SetTitleTextAppearance(this, Resource.Style.LightGrayTextMediumBold); SetSupportActionBar(toolbar); ActionBar actionBar = SupportActionBar; if (actionBar != null) { actionBar.SetDisplayHomeAsUpEnabled(true); actionBar.SetHomeButtonEnabled(true); actionBar.SetHomeAsUpIndicator(Android.Resource.Drawable.IcMenuCloseClearCancel); actionBar.Title = dlg.Title; } appBarLayout = new AppBarLayout(this); appBarLayout.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); appBarLayout.AddView(toolbar); fragmentView = new FragmentContainerView(this); fragmentView.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); fragmentView.Id = FragmentViewId; var scrollViewLayoutParams = new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); scrollViewLayoutParams.Behavior = new AppBarLayout.ScrollingViewBehavior(this, null); scrollView = new NestedScrollView(new ContextThemeWrapper(this, Resource.Style.DarkBackgroundStyle)); scrollView.LayoutParameters = scrollViewLayoutParams; scrollView.AddView(fragmentView); coordLayout = new CoordinatorLayout(this); coordLayout.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); coordLayout.AddView(appBarLayout); coordLayout.AddView(scrollView); SetContentView(coordLayout); SupportFragmentManager.BeginTransaction().SetReorderingAllowed(true).Add(fragmentView.Id, dlg.Properties, "PropertyDialog").Commit(); }
void AddToolbar(ViewGroup parent) { Toolbar toolbar = new Toolbar(this); var appbarLayout = new AppBarLayout(this); appbarLayout.AddView(toolbar, new ViewGroup.LayoutParams(AppBarLayout.LayoutParams.MatchParent, global::Android.Resource.Attribute.ActionBarSize)); SetSupportActionBar(toolbar); parent.AddView(appbarLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent)); }
protected virtual void LoadView(IShellContext shellContext) { Profile.FrameBegin(); var context = shellContext.AndroidContext; // Android designer can't load fragments or resources from layouts if (context.IsDesignerContext()) { _rootView = new FrameLayout(context); return; } var coordinator = LayoutInflater.FromContext(context).Inflate(Resource.Layout.FlyoutContent, null); Profile.FramePartition("Find Recycler"); _recycler = coordinator.FindViewById <RecyclerView>(Resource.Id.flyoutcontent_recycler); Profile.FramePartition("Find AppBar"); _appBar = coordinator.FindViewById <AppBarLayout>(Resource.Id.flyoutcontent_appbar); _rootView = coordinator as ViewGroup; Profile.FramePartition("Add Listener"); _appBar.AddOnOffsetChangedListener(this); Profile.FramePartition("Add HeaderView"); _actionBarHeight = (int)context.ToPixels(56); _flyoutHeader = ((IShellController)shellContext.Shell).FlyoutHeader; if (_flyoutHeader != null) { _flyoutHeader.MeasureInvalidated += OnFlyoutHeaderMeasureInvalidated; } _headerView = new HeaderContainer(context, _flyoutHeader) { MatchWidth = true }; _headerView.SetMinimumHeight(_actionBarHeight); _headerView.LayoutParameters = new AppBarLayout.LayoutParams(LP.MatchParent, LP.WrapContent) { ScrollFlags = AppBarLayout.LayoutParams.ScrollFlagScroll }; _appBar.AddView(_headerView); Profile.FramePartition("Recycler.SetAdapter"); _adapter = new ShellFlyoutRecyclerAdapter(shellContext, OnElementSelected); _recycler.SetClipToPadding(false); _recycler.SetLayoutManager(_layoutManager = new ScrollLayoutManager(context, (int)Orientation.Vertical, false)); _recycler.SetLayoutManager(new LinearLayoutManager(context, (int)Orientation.Vertical, false)); _recycler.SetAdapter(_adapter); Profile.FramePartition("Initialize BgImage"); var metrics = context.Resources.DisplayMetrics; var width = Math.Min(metrics.WidthPixels, metrics.HeightPixels); using (TypedValue tv = new TypedValue()) { if (context.Theme.ResolveAttribute(global::Android.Resource.Attribute.ActionBarSize, tv, true)) { _actionBarHeight = TypedValue.ComplexToDimensionPixelSize(tv.Data, metrics); } } width -= _actionBarHeight; coordinator.LayoutParameters = new LP(width, LP.MatchParent); _bgImage = new ImageView(context) { LayoutParameters = new LP(coordinator.LayoutParameters) }; Profile.FramePartition("UpdateFlyoutHeaderBehavior"); UpdateFlyoutHeaderBehavior(); _shellContext.Shell.PropertyChanged += OnShellPropertyChanged; Profile.FramePartition("UpdateFlyoutBackground"); UpdateFlyoutBackground(); Profile.FramePartition(nameof(UpdateVerticalScrollMode)); UpdateVerticalScrollMode(); Profile.FrameEnd(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); var info = FamiStudioForm.Instance != null ? FamiStudioForm.Instance.ActiveDialog as TutorialDialogActivityInfo : null; if (savedInstanceState != null || info == null) { Finish(); return; } var appBarLayoutParams = new AppBarLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, DroidUtils.GetSizeAttributeInPixel(this, Android.Resource.Attribute.ActionBarSize)); appBarLayoutParams.ScrollFlags = 0; toolbar = new AndroidX.AppCompat.Widget.Toolbar(new ContextThemeWrapper(this, Resource.Style.ToolbarTheme)); toolbar.LayoutParameters = appBarLayoutParams; toolbar.SetTitleTextAppearance(this, Resource.Style.LightGrayTextMediumBold); SetSupportActionBar(toolbar); ActionBar actionBar = SupportActionBar; if (actionBar != null) { actionBar.Title = "Welcome to FamiStudio!"; } appBarLayout = new AppBarLayout(this); appBarLayout.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); appBarLayout.AddView(toolbar); var margin = DroidUtils.DpToPixels(10); var linearLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); linearLayoutParams.Gravity = GravityFlags.Center; linearLayoutParams.SetMargins(margin, margin, margin, margin); textView = new TextView(new ContextThemeWrapper(this, Resource.Style.LightGrayTextMedium)); textView.Text = TutorialMessages[0]; textView.LayoutParameters = linearLayoutParams; webView = new MaxHeightWebView(this); webView.LayoutParameters = linearLayoutParams; var coordLayoutParams = new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);; coordLayoutParams.Behavior = new AppBarLayout.ScrollingViewBehavior(this, null); var linearLayout = new LinearLayout(new ContextThemeWrapper(this, Resource.Style.DarkBackgroundStyle)); linearLayout.LayoutParameters = coordLayoutParams; linearLayout.Orientation = Android.Widget.Orientation.Vertical; linearLayout.AddView(textView); linearLayout.AddView(webView); coordLayout = new CoordinatorLayout(this); coordLayout.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); coordLayout.AddView(appBarLayout); coordLayout.AddView(linearLayout); RefreshPage(); SetContentView(coordLayout); }