我以编程方式创建了此类元素的列表(没有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()的元素为红色,但其他所有元素均为灰色,无论我选择哪种颜色(即使再次是相同的红色)也是如此。
这是为什么?