我很难在 Xamarin Studio 中编译我的 Android 应用程序。出现的错误如下:
No resource found that matches the given name attr "colorPrimary"
它指的是我的 styles.xml:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="@android:style/Theme.Material.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<!--item name="colorPrimaryDark">@color/colorPrimaryDark</item-->
<!--item name="colorAccent">@color/colorAccent</item-->
</style>
</resources>
在网上找到的通常建议是将 SDK 版本设置为 21 或更高版本。但我已经尝试过了:
- 在 list 中将 minSdkVersion 设置为 21
- 在 list 中将 targetSdkVersion 设置为 21
- 在项目设置中将目标框架设置为 Android 5.0
- 清理并重建项目
错误仍然存在:-( 是否需要其他设置才能使其正常工作?
最佳答案
这对我的项目有用。
在res/values-v21/styles.xml
中,
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="AppTheme" parent="@android:style/Theme.Material.Light.DarkActionBar">
<item name="android:colorPrimary">@color/primaryColor</item>
</style>
</resources>
在res/values/styles.xml
中,
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primaryColor</item>
</style>
</resources>
关于android - 找不到与给定名称 attr "colorPrimary"匹配的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38996638/