【问题标题】:No resource found that matches the given name at android:colorForegroundInverse with value @color/foreground_material_light未找到与 android:colorForegroundInverse 中的给定名称匹配且值为 @color/foreground_material_light 的资源
【发布时间】:2017-05-09 05:45:41
【问题描述】:

我想通过覆盖主题来更改我的应用程序中的颜色。我有几个主题可供用户选择。尝试覆盖主题时,我在 Android Studio 中收到此错误:

在 android:colorForegroundInverse 上找不到与给定名称匹配且值为 @color/foreground_material_light 的资源

值\styles.xml

<resources>
    <style name="LigthTheme" parent="@style/Theme.AppCompat">
<!--    <item name="colorPrimary">@color/aztec_gold</item>
    <item name="colorPrimaryDark">@color/licorice</item>
    <item name="colorAccent">@color/accent_material_light</item>
    <item name="android:itemBackground">@color/aztec_gold</item>
    <item name="android:background">@color/aztec_gold</item>
    -->
</style>

<style name="RetroTheme" parent="@style/Theme.AppCompat">
    <!-- Customize your theme here. -->
    <item name="colorPrimaryDark">@color/nickel</item>
    <item name="colorPrimary">@color/spanish_gray</item>
    <item name="colorAccent">@color/turtle_green</item>
    <item name="android:windowBackground">@color/white_smoke</item>
    <item name="android:colorBackground">@color/white_smoke</item>
    <item name="android:textColorPrimary">@color/black</item>
    <item name="android:textColorSecondary">@color/black_light</item>
    <item name="android:textColorSecondaryInverse">@color/white</item>
    <item name="android:textColorPrimaryInverse">@color/white_smoke</item>
    <item name="android:colorForeground">@color/white_smoke</item>
    <item name="colorButtonNormal">@color/june_bud</item>
    <item name="android:colorForegroundInverse">@color/white_smoke</item>
</style>


<style name="DarkTheme" parent="@style/Theme.AppCompat">
<!--        <item name="colorPrimary">@color/aztec_gold</item>
    <item name="colorPrimaryDark">@color/licorice</item>
    <item name="colorAccent">@color/accent_material_light</item>
    <item name="android:itemBackground">@color/aztec_gold</item>
    <item name="android:background">@color/aztec_gold</item>
    -->
</style>

值\colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="spanish_gray">#9e9e9e</color>
    <color name="pastel_gray">#cfcfcf</color>
    <color name="nickel">#707070</color>
    <color name="june_bud">#aed851</color>
    <color name="pale_goldenrod">#e1ffb1</color>
    <color name="turtle_green">#7da453</color>
    <color name="white_smoke">#f5f5f5</color>
    <color name="black">#d2000000</color>
    <color name="black_light">#9c000000</color>
    <color name="black_light1">#9c000000</color>
    <color name="white">#ffffff</color>
</resources>

build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "25.0.2"

defaultConfig {
    applicationId "com.ivan.vts.mapper"
    minSdkVersion 16
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    jackOptions {
        enabled true
    }

}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    targetCompatibility JavaVersion.VERSION_1_8
    sourceCompatibility JavaVersion.VERSION_1_8
}

dexOptions {
    javaMaxHeapSize "2048M"
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile group: 'com.google.code.gson', name: 'gson', version: '2.4'
compile group: 'commons-io', name: 'commons-io', version: '2.5'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.google.android.gms:play-services-location:10.2.4'
compile 'com.google.android.gms:play-services-maps:10.2.4'
compile 'com.google.android.gms:play-services-places:10.2.4'
compile 'com.android.support:multidex:1.0.1'
compile 'cn.pedant.sweetalert:library:1.3'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.maps.android:android-maps-utils:0.4.+'
testCompile 'junit:junit:4.12'
}

尝试将 colorForegroundInverse 和 foreground_material_light 放在styles.xml、colors.xml 中,将父级设置为不同的主题bt 总是相同的错误。 提前致谢。

编辑: 我可以在 colors.xml 中添加类似: &lt;color name="foreground_material_light"&gt;#fff&lt;/color&gt; 并且有警告,但没有错误。我觉得不合适。

【问题讨论】:

    标签: android themes


    【解决方案1】:

    您可以尝试访问颜色为 @android:color/foreground_material_light

    【讨论】:

    • 无法访问,因为它不存在。所以我会更新我的问题。
    • 在您的 gradle 依赖项中添加 compile 'com.android.support:appcompat-v7:25.0.1'
    猜你喜欢
    • 1970-01-01
    • 2016-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多