【问题标题】:Xamarin Android Support Library custom StylesXamarin Android 支持库自定义样式
【发布时间】:2017-02-23 10:05:02
【问题描述】:

我有一个带有 Minimum Android Version: 2.3 (API Level 10 - Gingerbread)Compile Android Version: 6.0 (Marshmallow) 的 Android 应用程序 (Xamarin/Visual Studio)。

我尝试支持所有这些 Android 版本,同时保持我的应用的 Material Design 外观。

我尝试使用支持库(来自 NuGet:Xamarin.Android.Support.v7.AppCompat 版本 23Xamarin.Android.Support.v7.CardView 版本 23),并将它们添加到我的项目中。

现在,我为 CardViews 创建了 3 个自定义样式;在我的 Resources/values/styles.xml 中,我有以下代码:

  <?xml version="1.0" encoding="UTF-8"?>

  <resources>
    <!--A single normal lesson for the Timegrid-->
    <style name="Xamarin.Android.Support.v7.CardView.Lesson">
      <item name="cardBackgroundColor">@color/orange_500</item>
      <item name="cardCornerRadius">18dp</item>
    </style>

    <!--A single newly added lesson for the Timegrid-->
    <style name="Xamarin.Android.Support.v7.CardView.LessonNew">
      <item name="cardBackgroundColor">@color/green_500</item>
      <item name="cardCornerRadius">18dp</item>
    </style>

    <!--A single cancelled lesson for the Timegrid-->
    <style name="Xamarin.Android.Support.v7.CardView.LessonCancellation">
      <item name="cardBackgroundColor">@color/grey_500</item>
      <item name="cardCornerRadius">18dp</item>
    </style>

  </resources>

由于以下错误,我无法编译:

Severity Code Description Project File Line Suppression State Error Error retrieving parent for item: No resource found that matches the given name 'Xamarin.Android.Support.v7.CardView'.

我该如何解决这个问题? 提前致谢

【问题讨论】:

    标签: android xamarin android-support-library


    【解决方案1】:

    将样式父级设置为 CardView 并将您的 Name 更改为非点限定(本地)名称。

    样式示例:

    <style name="LessonNew" parent="CardView">
        <item name="android:layout_margin">10dp</item>
        <item name="cardCornerRadius">18dp</item>
        <item name="cardElevation">10dp</item>
    </style>
    

    【讨论】:

    • 我仍然收到此错误:Error retrieving parent for item: No resource found that matches the given name 'CardView'.
    • 是否需要添加thisthis支持库?
    • Xamarin.Android.Support.v7.CardView
    • 没有别的了吗?我只有从 NuGet 添加的 v7.CardView,但仍然收到无法找到 CardView 的错误。
    • @MarcR。这就是cardview...你可以直接在CardView上分配这些属性(即cardElevation)而不是使用样式吗?项目/应用程序编译和运行正常吗?如果是这样,Java cardview 支持库不是问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-17
    • 1970-01-01
    • 2016-03-22
    • 1970-01-01
    • 2016-07-16
    相关资源
    最近更新 更多