我正在开发Android应用程序。我想更改状态文本的颜色。它也是已知的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"/>
值\ 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'
})
}
如何解决我的问题?请帮帮我?
答案 0 :(得分: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>
答案 1 :(得分:0)
因为您忘记为textColorPrimary
和textColorSecondary
指定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>
答案 2 :(得分:-1)
在values
文件夹中应该有一个colors.xml文件,用于定义textColorPrimary
颜色,例如:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="textColorPrimary">#ff004080</color>
</resources>
将#ff004080
替换为您选择颜色的ARGB代码。