改变表行字体颜色

时间:2012-09-10 05:04:55

标签: android

我为自己的比赛取得了高分activity。我用表格行输出得分。我的问题是如何更改表格行中字体的颜色,因为我看不出输出是什么。

这是我的布局代码:

<TableLayout
        android:id="@+id/data_table"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:visibility="invisible"
        >

        <TableRow android:visibility="invisible" >

            <TextView
                android:layout_marginLeft="65dp"
                android:visibility="invisible"
                android:text="#"
                android:textColor="#000000" />


            <TextView
                android:visibility="invisible"
                android:text="Score"
                android:textColor="#000000" />


            <TextView
                android:visibility="invisible"
                android:text="Player"
                android:textColor="#000000" />

        </TableRow>
    </TableLayout>

以下是高分activity中输出的颜色。

enter image description here

我如何将灰色变为黑色?

这是我如何添加表格:

{
            TableRow tableRow= new TableRow(this);

            ArrayList<Object> row = data.get(position);

            TextView idText = new TextView(this);
            idText.setText(row.get(0).toString());
            tableRow.addView(idText);


            TextView textOne = new TextView(this);
            textOne.setText(row.get(1).toString());
            tableRow.addView(textOne);

            TextView textTwo = new TextView(this);
            textTwo.setText(row.get(2).toString());
            tableRow.addView(textTwo);

            dataTable.addView(tableRow);
        }

提前致谢

1 个答案:

答案 0 :(得分:0)

您需要在以编程方式创建TextView时指定文本颜色,否则Android将使用其默认(灰色)颜色。黑色是0xFF000000

TextView textOne = new TextView(this);
textOne.setTextColor(0xFF000000);
textOne.setText(row.get(1).toString());
tableRow.addView(textOne);

请注意,您可能需要use a color resource才能使其与其他TextView保持一致。