【问题标题】:No resource found that matches the given name: attr 'android:elevation'找不到与给定名称匹配的资源:attr 'android:elevation'
【发布时间】:2017-11-22 17:06:19
【问题描述】:

我正在尝试在 VS 和 Xamarin 上重建 Android 应用程序 但我收到此错误

找不到与给定名称匹配的资源:attr '机器人:海拔'。

这是属性:

<item name="android:elevation">@dimen/design_bottom_sheet_modal_elevation</item>

我使用这些值进行编译:

错误来自文件 values.xml,但有时文件中的不同属性会发生相同的错误; values-23.xml 或 22..etc

【问题讨论】:

    标签: android xamarin.android xamarin.forms


    【解决方案1】:

    将编译版本改为Android 5.0或以上。 海拔属性是在 5.0 中引入的。 所以 Kit-kat 构建工具会失败。

    【讨论】:

    • 我按照您的描述更改了编译版本:我摆脱了那个错误,但我得到了另一个错误:java.lang.OutOfMemoryError。考虑增加 $(JavaMaximumHeapSize) 的值。 Java在执行'java.exe时内存不足
    • @MohamedAhmed 转到您的 Android 选项 -> 高级选项卡 -> 高级 Android 构建设置并将 Java 堆大小设置为 1G,例如
    • @Amit Kumar,我一直在想......为什么他们甚至让人们在那里设置 KitKat 4.4?是否存在配置可行的方案?
    • 这些属性取决于编译器,这是在 Lollipop(5.0) 中引入的。始终建议使用最新的构建工具版本编译代码。由于 Kitkat 的市场份额很大,大多数应用仍然需要支持。
    【解决方案2】:

    Elevation 仅适用于 Android 5.x+,因此您必须更改编译以使用 5.0 或更高版本。

    您的 /Resources/values/style.xml 应该或多或少类似于:

    <?xml version="1.0" encoding="utf-8" ?>
    <resources>
      <style name="MyTheme" parent="MyTheme.Base">
      </style>
      <style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <!--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">#00FFAA</item>
        <!-- colorPrimaryDark is used for the status bar -->
        <item name="colorPrimaryDark">#004D40</item>
        <!-- colorAccent is used as the default value for colorControlActivated
             which is used to tint widgets -->
        <item name="colorAccent">@color/accent</item>
        <!-- You can also set colorControlNormal, colorControlActivated
             colorControlHighlight and colorSwitchThumbNormal. 
        <item name="colorControlNormal">#00897B</item>
        <item name="colorControlActivated">#1DE9B6</item>-->
        <item name="windowActionModeOverlay">true</item>
      </style>
    </resources>
    

    同时检查 /Resources/values 文件夹中的 style.xml,确保为 API 级别 v21+ 设置样式,如下所示:/Resources/values-v21/style.xml

    <?xml version="1.0" encoding="utf-8" ?>
    <resources>
      <!--
            Base application theme for API 21+. This theme replaces
            MyTheme from resources/values/styles.xml on API 21+ devices.
        -->
      <style name="MyTheme" parent="MyTheme.Base">
        <item name="android:windowContentTransitions">true</item>
        <item name="android:windowAllowEnterTransitionOverlap">true</item>
        <item name="android:windowAllowReturnTransitionOverlap">true</item>
        <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
        <item name="android:windowSharedElementExitTransition">@android:transition/move</item>
      </style>
    </resources>
    

    【讨论】:

      【解决方案3】:

      在 BuildAction 中为所有 style.xml 和图像文件设置属性为 AndroidResource。请记住,所有文件都必须位于 .Droid 项目的 Resources 文件夹中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-10-13
        • 2018-03-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多