Bor*_*ris 13 android xamarin.android xamarin
我很难在Xamarin Studio中编译我的Android应用程序.出现的错误如下:
找不到与给定名称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>
Run Code Online (Sandbox Code Playgroud)
在线发现的通常建议是将SDK版本设置为21或更高版本.但我已经尝试过了:
错误仍然存在:-(是否还需要其他设置才能使其工作?
K N*_*Lal 14
这对我的项目有用.
在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>
Run Code Online (Sandbox Code Playgroud)
在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>
Run Code Online (Sandbox Code Playgroud)
您应该直接从Material Design文档(https://developer.android.com/training/material/theme.html#ColorPalette)遵循约定:
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">@color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">@color/accent</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
您在这里缺少的是项目的android:名称空间前缀colorPrimary.因此,它无法找到相应的属性,因为它未在范围中定义.
否则,您需要android:从主题中删除前缀
parent="@android:style/Theme.Material.Light.DarkActionBar"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
43126 次 |
| 最近记录: |