No resource found that matches the given name: attr 'android:elevation'

19,802

Solution 1

Change the compilation version to Android 5.0 or above. elevation attribute was introduced in 5.0. So Kit-kat build tools will fail.

Solution 2

Elevation is only for Android 5.x+ so you must change compilation to use 5.0 or above.

your /Resources/values/style.xml should look more or less like:

<?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>

Also check your style.xml in your /Resources/values folder and make sure you set styles for API level v21+ look like: /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>
Share:
19,802
mshwf
Author by

mshwf

A software developer who is interested in cross-platform development. I created three NuGet packages: Mshwf.Charger, Mshwf.NiceLinq and Xamlly

Updated on June 14, 2022

Comments

  • mshwf
    mshwf almost 2 years

    I'm trying to rebuild an Android application on VS and Xamarin but I get this error

    No resource found that matches the given name: attr 'android:elevation'.

    this is the attribute:

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

    I use these values for compiling:

    enter image description here

    the error comes from the file values.xml, but sometimes the same error happens with different attributes in files; values-23.xml or 22..etc