【发布时间】:2015-11-09 07:21:47
【问题描述】:
最近我们将应用中的 targetSDK 从 21 更新到了 23。
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
...
defaultConfig {
applicationId 'com.myapp'
minSdkVersion 15
targetSdkVersion 23
versionCode System.getenv("LAST_BUILD_NUMBER") as Integer ?: 1514261001
versionName '2.6.1' + (System.getenv("APP_VERSION_SUFFIX") ?: '')
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
multiDexEnabled true
}
我们的应用还有一些小部件,其中包含一些像这样的 TextView:
<TextView
android:id="@+id/txt_sunrise"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_classic_weather_sunrise"
android:drawablePadding="6dp"
android:text="-"
android:textColor="@android:color/white"
android:textSize="@dimen/largeTextSizeAstro" />
小部件是以这种方式构建的:
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_large);
rv.setTextViewText(R.id.txt_sunrise, sunrise);
// some more code
appWidgetManager.updateAppWidget(appWidgetId, rv);
在 Android 5.0 上一切正常,但在一些 Android 4.x 设备上(我可以在一些三星设备以及 Genymotion 模拟器上重现它),当小部件应该被构建时,我遇到了一个异常:
caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x2/d=0x7f01018e a=2}
at android.content.res.Resources.loadColorStateList(Resources.java:2074)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
at android.widget.TextView.<init>(TextView.java:912)
at android.widget.TextView.<init>(TextView.java:578)
当我检查给定的资源-Id 0x7f01018e 时,发现这是应用程序主题中定义的 colorAccent,当然不是颜色状态列表
<style name="AppTheme" parent="Theme.AppCompat">
<item name="colorPrimary">@color/grey_darker</item>
<item name="colorPrimaryDark">#111111</item>
<item name="colorAccent">@color/orange</item>
知道吗,为什么会出现这个错误?
【问题讨论】: