【问题标题】:changing table row font color更改表格行字体颜色
【发布时间】:2012-09-10 05:04:55
【问题描述】:

我的游戏获得了高分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 中输出的颜色。

如何将灰色变为黑色?

这是我添加表格的方法:

{
            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);
        }

提前致谢

【问题讨论】:

  • 您能说明一下您是如何添加表格行的吗?

标签: android


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2014-06-26
    • 2019-09-24
    • 2017-10-30
    • 2018-04-07
    • 2013-05-08
    • 2011-12-24
    • 2018-05-11
    • 2013-11-14
    • 2014-01-19
    相关资源
    最近更新 更多