我已经通过编程创建了TextView
,现在我想将文本颜色设置为TextView
,以下是我的代码:
TableLayout ll = (TableLayout) findViewById(R.id.auditContent);
public TableRow row;
TextView txtNumber;
for (int i = 0; i < ItemCount; i++) {
row = new TableRow(MainActivity.this);
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
row.setLayoutParams(lp);
row.setWeightSum(1f);
txtNumber = new TextView(MainActivity.this);
txtNumber.setGravity(Gravity.CENTER);
txtNumber.setText("No." + count);
txtNumber.setTextColor(getResources().getColor(R.color.blue)); //setting text color
row.addView(txtNumber);
ll.addView(row, i);
}
textcolor
没有将颜色设置到TextView
文本中,我做错了什么。我调试了代码,但没有错误。请帮忙,谢谢。
在string.xml中:
<color name="blue">#33CCCC</color>
我没有使用color.xml。上述颜色对于xml的TextView
可以正常工作。