【发布时间】:2017-07-09 20:38:22
【问题描述】:
我在完成 Xamarin.Forms 应用程序时遇到了问题。
目前,我正在尝试对 Android 服务进行单元测试。
所以目前这意味着我在这一点上做了以下事情:
- 删除了 iOS 项目的默认 Xamarin 表单应用程序
- 创建的 PCL 中的基本表单
- 在 Xamarin.Forms PCL 中创建样式
- 在 Xamarin.Forms.Droid 项目中有基本主题
完成之后,我创建了 Xamarin UITest Android 项目
现在,我添加了对 Xamarin Forms.Droid 项目的引用
每次我启动必须在 Android 模拟器中运行的单元测试时,都找不到主题。
在驻留在 PCL 中的 app.xml 中
<Application.Resources>
<!-- Application resource dictionary -->
<ResourceDictionary>
<Color x:Key="BackgroundGlobal">#ff333333</Color>
<Color x:Key="MidGradient">#ff0d0d0d</Color>
<Color x:Key="BottomGradient">Black</Color>
<Color x:Key="MenuTextColor">Azure</Color>
<Style TargetType="ImageCell" x:Key="Clicky">
<Setter Property="TextColor" Value="{StaticResource MenuTextColor}"/>
<Setter Property="DetailColor" Value="Aqua"/>
</Style>
</ResourceDictionary>
</Application.Resources>
在 Xamarin.Forms.Droid Resource\Values\strings.xml 中
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MainTheme" parent="MainTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MainTheme.Base" parent="Theme.AppCompat">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#2196F3</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#1976D2</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#FF4081</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="windowActionModeOverlay">true</item>
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#FF4081</item>
</style>
</resources>
我目前得到以下信息:
Severity Code Description Project File Line Suppression State Error
Error: No resource found that matches the given name (at 'theme' with value '@style/MainTheme'). Xamarin.Forms.Droid.Tests C:\dev\git\example\Xamarin.Forms.Droid.Tests\obj\Debug\android\manifest\AndroidManifest.xml 9
【问题讨论】:
-
styles.xml 中是否存在 MainTheme?你可以在 Resource -> values -> styles.xml 中看到它。
-
根据请求,我更新了显示来自 Xamarin.Forms.Droid 的 pcl 样式和字符串/主题的示例。此外,测试项目是默认设置的 Xamarin.Forms.Android 和测试项目的资源/依赖项。
标签: c# unit-testing xamarin.android xamarin.forms