我写了一个应用程序,它依赖于资源中定义的颜色。有些是直接在布局XML文件中设置的,有些是在代码中设置的。例子:android:textColor不再适用于棉花糖
颜色定义res/values/styles.xml
:
<color name="orvGyro">#33B5E5</color>
布局:
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dotSpace"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/orvGyro" />
颜色代码:
accStatus.setTextColor(getResources().getColor(R.color.somecolor));
的应用目标API 17.截至棒棒糖,这有完美地工作,显示正确的颜色。迁移到棉花糖(Cyanogenmod 13)后,所有这些颜色显示为橙色。其他颜色,在Java代码中定义,而不是在资源中,似乎正确显示。
我已经尝试将目标API更改为23并添加样式API 21 +,无济于事。
这里有什么问题?这是CyanogenMod13中的错误,还是我做错了什么?
编辑:看起来这不是从资源中获取颜色。硬编码的颜色如下图所示也使我的橙色的文字:
<TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dotSpace"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#669900" />
编辑2:跨越Android M Developer Preview - TextView android:textColor being ignored刚刚来到。这可以解释我正在经历的行为吗?
编辑3:当我动态生成内容而不是使用布局时,颜色正确显示。例如:
TextView newType = new TextView(rilLteCells.getContext());
newType.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 2));
newType.setTextAppearance(rilLteCells.getContext(), android.R.style.TextAppearance_Medium);
newType.setTextColor(rilLteCells.getContext().getResources().getColor(getColorFromGeneration(cell.getGeneration())));
newType.setText(rilLteCells.getContext().getResources().getString(R.string.smallDot));
row.addView(newType);
如果我直接在布局中设置颜色,我该怎么做? – user149408
它将从您的色彩资源中选取合适的颜色。 –
这正是不起作用的。即使在布局中指定颜色资源时,它也会显示为橙色。 – user149408