【发布时间】:2011-09-04 20:35:00
【问题描述】:
我以编程方式创建此类元素的列表(不是 ListView,只是将它们添加到父级):
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:layout_weight="1">
<TextView android:id="@+id/filiale_name"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:id="@+id/lagerstand_text"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:textSize="10sp" android:textColor="@color/red"/>
</LinearLayout>
另外,我在 values/colors.xml 中定义了一些颜色。如您所见,ID 为“lagerstand_text”的 TextView 默认将其颜色设置为红色。这行得通。
在 Java 中创建元素时,我会这样做
lagerstandText.setText("bla");
对于某些元素我也这样做
lagerstandText.setTextColor(R.color.red);
和其他颜色。虽然我不调用 setTextColor() 的元素是红色的,但所有其他元素都是灰色的,无论我选择哪种颜色(即使它再次是相同的红色)。
这是为什么呢?
【问题讨论】: