未找到与给定名称匹配的资源'android:Theme.Material.Light.DarkActionBar'



我尝试改变我的HelloWorld应用holo主题为Material.Light.DarkActionBar主题(如所说的新的Android开发工具会议)。但我有以下错误。我尝试更改目标SDK版本为21。但是我们在SDK管理器中没有21个SDK。在那次会议上,他们说,为v-21设置样式xml。

值/styles.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>
</resources>

values-v21/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    !-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>
</resources>

build.gradle

apply plugin: 'com.android.application'
android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"
    defaultConfig {
        applicationId "com.ramapps.helloworld"
        minSdkVersion 15
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

错误:

Error:Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Light.DarkActionBar'.
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Applications/Android Studio.app/sdk/build-tools/android-4.4W/aapt package -f --no-crunch -I /Applications/Android Studio.app/sdk/platforms/android-20/android.jar -M /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/intermediates/manifests/debug/AndroidManifest.xml -S /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/intermediates/res/debug -A /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/intermediates/assets/debug -m -J /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/generated/source/r/debug -F /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/intermediates/libs/app-debug.ap_ --debug-mode --custom-package com.ramapps.helloworld -0 apk
  Error Code:
    1
  Output:
    /Users/Ram_PC/Ram/MyDrive/My_Workspaces/Android_Studio_Workspace_L/HelloWorld/app/build/intermediates/res/debug/values-v21/values.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Light.DarkActionBar'.

您可以尝试像这样设置build.gradle中的值(针对API 25更新):

android {
  compileSdkVersion 25
  buildToolsVersion "25.0.3"
  defaultConfig {
    minSdkVersion 21 //oldest version you would like to support
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    ...
  }
}

我们不能在L设备上安装针对L预览的应用程序。

res/values/styles.xml, Theme.Material.Light改为Theme.Light,并跟随build.gradle

android {
    compileSdkVersion 20
    buildToolsVersion '20.0.0'
    defaultConfig {
        applicationId 'com.example.android.market.licensing'
        minSdkVersion 13
        targetSdkVersion 20
        versionCode 1
        versionName '1.0'
    }

虽然Theme.Material.Light是20sdk版本的一部分,但不知何故它不适合我。

从AssemblyMenifest.xml设置应用程序的目标为API Level 21或在AssemblyMenifest.xml中添加<uses-sdk android:targetSdkVersion="21" android:minSdkVersion="19" />标签

我更改了Theme.Material。光照主题。轻,它为我工作。

我认为这里的问题是,你需要设置你的buildToolsVersion pre Android L版本。

Here my gradle

apply plugin: 'com.android.application'
android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"
    defaultConfig {
        applicationId "com.mayuonline.ribbit"
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    // You must install or update the Support Repository through the SDK manager to use this dependency.
    compile 'com.android.support:support-v13:19.+'
}

还要确保将styles.xml更改为如下

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="android:Theme.Light">
    </style>
</resources>

这应该能解决问题。

最新更新