【问题标题】:android error No resource found that matches in textColorPrimaryandroid错误在textColorPrimary中找不到匹配的资源
【发布时间】:2017-04-26 11:20:20
【问题描述】:

我正在开发安卓应用。我想更改状态文本的颜色。它也称为 textColorPrimary。但显示错误。

Error:(829, 21) No resource found that matches the given name: attr 'textColorPrimary'.
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt

我的代码如下所示。

AndroidManifest.xml

        <activity
        android:name=".home.HomeActivity"
        android:theme="@style/AppTheme.GrayStatusBar"/>

values\styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme.GrayStatusBar" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimaryDark">@color/colorGray</item>
    <item name="textColorPrimary">@color/bg</item>
</style>
</resources>

v21\styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>

v17\styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>

build.gradle

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    sourceSets.main {
        jniLibs.srcDir 'libs'
        jni.srcDirs = [] //disable automatic ndk-build call
    }

    android {
        useLibrary 'org.apache.http.legacy'
    }
    defaultConfig {
    applicationId "com.acs.udial"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 15770
    versionName "r15770"
    testApplicationId "com.test"
    testInstrumentationRunner "android.test.InstrumentationTestRunner"
}

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

lintOptions {
    abortOnError false
}
}

    allprojects {
    repositories {
    maven { url "https://jitpack.io" }
    }
}

dependencies {

    compile fileTree(dir: 'libs', include: ['*.jar'])

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
}

如何解决我的问题?请帮帮我?

【问题讨论】:

  • 发给你build.gradle..
  • 也许您的 textColorPrimary 在测试包内?
  • @rafsanahmad007 我已经添加了问题。请检查一下。
  • @resw67 那么如何解决这个问题。
  • 抱歉,我看到了。 DarkActionBar 首先有一个字段 textColorPrimary 吗?看看stackoverflow.com/questions/39070040/…

标签: android xml


【解决方案1】:

主题父改成parent="Theme.AppCompat.Light"解决的问题。所以现在 style.xml

<style name="AppTheme.GrayStatusBar" parent="Theme.AppCompat.Light">
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorPrimary">@color/colorPrimaryDark</item>
    <item name="android:textColor">@color/textColorPrimary</item>

</style>

【讨论】:

    【解决方案2】:

    因为您忘记为textColorPrimarytextColorSecondary 指定android。 请检查以下代码:

    <style name="ToolbarThemeDemo" parent="Theme.AppCompat.Light">
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="android:textColorSecondary">@android:color/white</item>
    </style>
    

    【讨论】:

      【解决方案3】:

      在您的values 文件夹中应该有一个colors.xml 文件来定义您的textColorPrimary 颜色,例如:

      <?xml version="1.0" encoding="utf-8"?>
      <resources>
          <color name="textColorPrimary">#ff004080</color>
      </resources>
      

      用您选择的颜色的 ARGB 代码替换 #ff004080

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多