如何在xamarin.forms中使用android材质设计?

如何在xamarin.forms中使用android材质设计?,xamarin,visual-studio-2015,xamarin.android,xamarin.forms,material-design,Xamarin,Visual Studio 2015,Xamarin.android,Xamarin.forms,Material Design,我正在Xamarin.form中使用可移植类。我想在我的android和ios移动应用程序中使用材质设计。但是我无法获得任何好的资源来使用xamarin.forms中的材质设计。有一个关于将AppCompat添加到xamarin.forms应用程序的指南。这将有助于支持材料设计主题 确保您正在使用>=Xamarin.Forms 2.0 确保您的Android项目是为Android 6.0(API 23)或更高版本编译的 添加新主题以支持材质设计 Resources/values/colors.

我正在Xamarin.form中使用可移植类。我想在我的android和ios移动应用程序中使用材质设计。但是我无法获得任何好的资源来使用xamarin.forms中的材质设计。

有一个关于将AppCompat添加到xamarin.forms应用程序的指南。这将有助于支持材料设计主题

  • 确保您正在使用>=Xamarin.Forms 2.0
  • 确保您的Android项目是为Android 6.0(API 23)或更高版本编译的
  • 添加新主题以支持材质设计
  • Resources/values/colors.xml

    Resources/layout/toolbar.axml


    Xamarin表单支持Android上的材质设计。它在iOS上不支持它,因为它不是iOS的东西,只是安卓的东西。我知道谷歌已经尝试在iOS上推广它,包括在他们的应用程序中,并发布了一个SDK,但是表单不太可能在iOS上支持它。只要搜索网页,你就会找到很多资源。这里有一篇来自Xamarin的关于在Xamarin中使用Android材质设计的博文。表单Thank you@JimBobBennett.Thank you。Xamarin文档中提到了这一点。除此之外的任何其他资源,如视频、博客或链接,都将对我有所帮助。如果有,请分享。这是如何做到的,但最新版本的Xamarin表单默认已使用材质设计。
    <resources>
      <color name="primary">#2196F3</color>
      <color name="primaryDark">#1976D2</color>
      <color name="accent">#FFC107</color>
      <color name="window_background">#F5F5F5</color>
    </resources>
    
    <resources>
      <style name="MyTheme" parent="MyTheme.Base">
      </style>
      <style name="MyTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primaryDark</item>
        <item name="colorAccent">@color/accent</item>
        <item name="android:windowBackground">@color/window_background</item>
        <item name="windowActionModeOverlay">true</item>
      </style>
    </resources>
    
    <resources>
      <style name="MyTheme" parent="MyTheme.Base">
        <!--If you are using MasterDetailPage you will want to set these, else you can leave them out-->
        <!--<item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>-->
      </style>
    </resources>
    
    <android.support.design.widget.TabLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/sliding_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:tabIndicatorColor="@android:color/white"
        app:tabGravity="fill"
        app:tabMode="fixed" />
    
    <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:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways" />
    
    protected override void OnCreate(Bundle bundle)
    {
      // set the layout resources first
      FormsAppCompatActivity.ToolbarResource = Resource.Layout.toolbar;
      FormsAppCompatActivity.TabLayoutResource = Resource.Layout.tabs;
    
      // then call base.OnCreate and the Xamarin.Forms methods
      base.OnCreate(bundle);
      Forms.Init(this, bundle);
      LoadApplication(new App());
    }