问题描述
我编写了一个依赖于资源中定义的颜色的应用程序。有些是直接在布局XML文件中设置的,有些是通过代码设置的。示例:
I have written an app which relies on colors defined in resources. Some are set directly in the layout XML file, others are set in code. Examples:
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为目标。直到Lollipop,它都可以完美工作,显示正确的颜色。迁移到棉花糖(Cyanogenmod 13)后,所有这些颜色都显示为橙色。其他颜色(用Java代码而不是资源定义)似乎可以正确显示。
The app targets API 17. Up to Lollipop, this has worked flawlessly, displaying the right colors. After migrating to Marshmallow (Cyanogenmod 13), all these colors display as orange. Other colors, which are defined in Java code and not in resources, seem to display correctly.
我尝试将目标API更改为23,并为API 21添加样式+,无济于事。
I've tried changing the target API to 23 and adding styles for API 21+, to no avail.
这是怎么了?这是CyanogenMod13中的错误,还是我做错了事?
What's wrong here? Is that a bug in CyanogenMod13, or am I doing something wrong?
编辑:似乎不是要从资源中获取颜色。如下所示对颜色进行硬编码也给了我橙色文字:
It seems it's not about getting the color from the resource. Hard-coding the colors as shown below also gives me orange text:
<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:刚遇到。
编辑3:当我动态生成内容而不是使用布局时,颜色可以正确显示。示例:
EDIT 3: When I generate content dynamically instead of using layouts, colors display correctly. Example:
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);
推荐答案
知道了。
无论我遇到此问题,控件中显示的文本都是单个正方形(U + 2b1b)。当我更改此文本时(例如,添加X),只有正方形将显示为橙色,字符串的其余部分具有所需的颜色。
Wherever I had this issue, the text displayed in the control was a single square (U+2b1b). When I alter this text (e.g. by appending an X), only the square will display in orange and the rest of the string has the desired color.
将其更改为小方块(U + 25fc)固定的东西。其他一些特殊字符会给我其他颜色-显然,某些字符在棉花糖上固定为某些颜色,而在早期版本中,它们的样式可以像其他任何文本一样。
Changing it to a small square (U+25fc) fixed things. Some other special characters would give me other colors – apparently certain characters are fixed to certain colors on Marshmallow, when on earlier versions they could be styled like any other text.
这篇关于android:textColor在棉花糖中不再起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!