Material Design For Xamarin.Forms
最近,升级 Xamarin.Forms 到最新版本后,发现Droid 项目下引入了以下几个依赖包:
Xamarin.Android.Support.Design
Xamarin.Android.Support.v7.AppCompat
Xamarin.Android.Support.v7.CardView
Xamarin.Android.Support.v7.MediaRouter
Material Design 是 Android 棒棒糖 带来的东西, 之前 Xamarin.Form 不支持它。
这几个依赖包,就是告诉我们:Xamarin.Form 也支持 Material Design 了!
但是编译,直接报错,错误主要集中在 Resource.Designer.cs 上,有几百个未定义!
开始以为不是最新的 Android SDK 引起的问题,可是安装 API Level 23 的 SDK 后, 问题依然。
翻来翻去,翻了两天,一直是这个问题,没有合适的答案.
今天找了一篇官方博客:
https://blog.xamarin.com/material-design-for-your-xamarin-forms-android-apps/
认真的对比了一下,除了这几个DLL的版本不一样外,其它都是照抄的,可是依然不行,甚至还提示:
Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.NoActionBar'.
试了试手动将以上几个DLL 降级到 23.0.1.3 (最新版本是 23.1.0 beta 版),Xamarin.Forms 降级到 1.5.1.6471 (最新版本是 1.5.2.6477-pre2)
重新编译神一般的通过了,看来 pre 版,beta 版最好是不要试,出了问题都不知道哪里的。。。
看一下效果:Android 5.1
Android 4.2
几乎一样,虽然 Material 是5.0的东西,但是在 4.2 上也有一样的效果。这应归功于 Android.Support.v7.AppCompat, 具体不了解,请 Android 大侠勿喷。
与之前的非 Material 支持对比,这里最大的变化之处就是支持左右滑动切换页面了,之前必须是点击标签头,才能切换。那时我还费尽心思的想自己弄个自定义 Renderer 呢,现在不用了。
------------------------------------
好啦,上面是费话, 进入正题: Xamarin.Forms 如何 Material
1, 更新相关 DLL
2, Resources/values/styles.xml
<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> </style> </resources>
2, Resources/values-v21/styles.xml
<resources> <style name="MyTheme" parent="MyTheme.Base"> <item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:statusBarColor">@android:color/transparent</item> </style> </resources>
3, Resources/values/colors.xml
<resources> <color name="primary">#2196F3</color> <color name="primaryDark">#1976D2</color> <color name="accent">#FFC107</color> <color name="window_background">#F5F5F5</color> </resources>
4, Resources/layout/toolbar.xml
<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" />
5,Resources/layout/tabs.xml
<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" />
6, MainActivity.cs
[Activity(Label = "蓝色理想", Theme = "@style/MyTheme", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] public class MainActivity : FormsAppCompatActivity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); global::Xamarin.Forms.Forms.Init(this, bundle); 8 FormsAppCompatActivity.ToolbarResource = Resource.Layout.toolbar; 9 FormsAppCompatActivity.TabLayoutResource = Resource.Layout.tabs; LoadApplication(new App(IoC.Get<SimpleContainer>())); } }
Theme="@style/MyTheme" 即 styles.xml 中扩展出来的 style
FormsAppCompatActivity 代替原来的 FormsApplicationActivity
具体请参考:
https://github.com/gruan01/Discuz.Mobi/tree/master/Discuz/Discuz.Droid
有一个小问题: 页签(tabs)文字超长时,会换行, 不用 Material 的时候, 超过部份可以滑动, 而现在是换行, 不可滑动.
-----------------
OK, 完,
Material Design For Xamarin.Forms的更多相关文章
- Xamarin.Forms 开发资源集合(复制)
复制:https://www.cnblogs.com/mschen/p/10199997.html 收集整理了下 Xamarin.Forms 的学习参考资料,分享给大家,稍后会不断补充: UI样式 S ...
- Xamarin.Forms 开发资源集合
收集整理了下 Xamarin.Forms 的学习参考资料,分享给大家,稍后会不断补充: UI样式 Snppts: Xamarin Forms UI Snippets. Prebuilt Templat ...
- xamarin forms中的Button文本默认大写
问题来源 使用xamarin forms创建的android项目中,Button.Toolbar的右侧菜单按钮上的如果是字母的话,在android5.0以上,默认的文本都是大写,这种情况iOS项目不存 ...
- Xamarin.Forms 入门
介绍 Xamarin.Forms是一个开源UI框架,Xamarin.Forms允许开发人员从单个共享代码库构建Android,iOS和Windows应用程序. Xamarin.Forms允许开发人员使 ...
- xamarin.forms新建项目android编译错误
vs2015 update3 新建的xamarin.forms项目中的android项目编译错误.提示缺少android_m2repository_r22.zip,96659D653BDE0FAEDB ...
- 仿知乎app登录界面(Material Design设计框架拿来就用的TexnInputLayout)
在我脑子里还没有Material Design这种概念,就我个人而言,PC端应用扁平化设计必须成为首选,手当其冲的两款即时通讯旺旺和QQ早就完成UI扁平化的更新,然而客户端扁平化的设计本身就存在天生的 ...
- Creating Reusable XAML User Controls with Xamarin Forms
In the previous post on making fancy layouts with Xamarin Forms we saw how you can design a Dashboar ...
- 菜鸟的Xamarin.Forms前行之路——从新建项目到APP上架各种报错问题解决方法合集(不定时更新)
出自:博客园-半路独行 原文地址:http://www.cnblogs.com/banluduxing/p/7425791.html 本文出自于http://www.cnblogs.com/banlu ...
- Xamarin Forms:小马过河,王者归来
因为我媳妇的原因,去年下半年从零开始学习Android原生开发,做了一个答题库app.整体给我的感觉是入门难度不大,前期折腾一番,大部分时间都是花在开发上面,其实任何一门语言都是如此. 今年我又有另一 ...
随机推荐
- CentOS6.5(Python-2.7.12)安装Pip
1.安装setuptools(下载链接可从https://pypi.python.org/pypi/setuptools#code-of-conduct寻找) #Download setuptools ...
- Swing应用开发实战系列之四:组件内容实时刷新问题
窗口组件动态刷新问题,在dotnet中根本不算什么问题,用几句代码很轻松就能搞定,但是在Swing中,实现动态刷新组件内容却是一件颇为吃力的事情.譬如针对我们经常用到的刷新JLable.JTextFi ...
- MyEclipse中SVN的常见的使用方法
本次主要内容: 一 .导入项目 (Checkout).从svn资源库检出 二 .更新 (Update) 三.锁(对要修改的文件加锁,防止文件冲突) 四.提交(项目修改后的提交) 五.解锁 六.查看历史 ...
- spring mvc 配置文件拦截器过滤url
最近在用spring mvc拦截器,sprin 版本号4.0.6.RELEASE, <mvc:interceptor> <mvc:mapping path="/admin/ ...
- 10901 Missile
10901 Missile 时间限制:1000MS 内存限制:65535K提交次数:40 通过次数:7 Description Long, long ago, country A invented ...
- C++ string的大小写转换
将一个string转换成大写或者小写,是项目中经常需要做的事情,但string类里并 没有提供这个方法.自己写个函数来实现,说起来挺简单,但做起来总让人觉得不方便.打个比方:早上起来想吃个汉堡,冰箱里 ...
- 迅为4412开发板Linux驱动教程——总线_设备_驱动注册流程详解
本文转自:http://www.topeetboard.com 视频下载地址: 驱动注册:http://pan.baidu.com/s/1i34HcDB 设备注册:http://pan.baidu.c ...
- Linux shell basic2 cat find tr
Cat stands for concatenate. Case 1. When the text files have more blank lines, we want to remove the ...
- Sql Practice 2
之前写了一个SP用来向dimention table插入0 -1 dummy row的值,但今天在process adventureworksdw2008示例 数据库的时候报错,查看了一下,是因为自己 ...
- Ngrok远程桌面及ssh配置
上一篇Ngrok 内网穿透利器 使用教程我们讲到Ngrok的基本使用教程,这篇描述一下Ngrok的远程桌面及ssh配置 Step 1 修改配置文件ngrok.cfg server_addr: &quo ...