【问题标题】:Gmail like navigation drawer (master page) in xamarin.formsxamarin.forms 中的 Gmail 类似于导航抽屉(母版页)
【发布时间】:2016-04-26 19:23:45
【问题描述】:

我目前正在使用 MVVMlight 在 xamarin.forms 中使用主详细信息页面,它基于 os 的默认行为呈现,它完美呈现了我想要的内容,但在 android 主页面中从导航栏下方开始。我希望母版页像 ios 一样覆盖整个屏幕高度,如果没有自定义渲染器,是否有任何方法或解决方案,或者是否有必要为此编写自定义渲染器

【问题讨论】:

  • 对于 android,您可以将 Theme = "@android:style/Theme.Black.NoTitleBar.Fullscreen") 放入您的活动中
  • 在这种情况下导航栏将不可见,但我希望导航栏也可见
  • 你说你想要全屏
  • 我希望母版页采用全屏而不是详细页
  • 嗯嗯,我不知道该怎么做,但我知道你可以在 android 上设置一些标志来显示/隐藏导航栏。 developer.android.com/training/system-ui/navigation.html 有更多信息。您也许可以在表单项目中设置“显示全屏”事件和“退出全屏”事件,并在 android 项目中实现它们以设置这些标志。

标签: xamarin xamarin.forms navigation-drawer xamarin.mobile


【解决方案1】:

使用 FormsAppCompatActivity 而不是 FormsApplicationActivity。

定义你自己的toolbar.axml

toolbar.axml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:minHeight="?attr/actionBarSize"
    android:contentInsetStart="0dp"
    android:contentInsetLeft="0dp"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:layout_scrollFlags="scroll|enterAlways">
</android.support.v7.widget.Toolbar>

设置自己的ToolbarResource

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            ToolbarResource = Resource.Layout.toolbar;
            base.OnCreate(bundle);
            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());
        }
    }

【讨论】:

  • 对于从 FormsApplicationActivity 而不是 FormsAppCompatActivity 派生的活动,我可以使用相同的抽屉吗?
  • 使用 FormsApplicationActivity 创建类似的抽屉很困难,因为您必须编写自定义项目级代码,并且非常复杂,尤其是导航抽屉。
【解决方案2】:

是的,你可以。检查这些链接。他们都使用 MasterDetail 页面来创建导航抽屉。只有 Detail 页面成为主页面视图,而 Master 页面成为滑动菜单。这实际上相当简单。还有其他几个很好的例子。但是,我认为您可以通过我列出的 3 个链接完成工作。如果不尝试像 How can I create a Navigation Drawer in Xamarin Forms 这样的搜索。

http://www.meritsolutions.com/mobile-development/implementing-navigation-drawer-in-xamarinforms/

https://www.syntaxismyui.com/xamarin-forms-masterdetail-page-navigation-recipe/

http://blog.falafel.com/xamarin-creating-a-sliding-tray/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-18
    • 2020-01-16
    • 2020-01-15
    相关资源
    最近更新 更多