0

プログラムでTableLayoutを作成しました。すべてがうまく機能しています。背景色とテキスト色を除く。TableLayoutの背景色を黒にし、各TextViewのテキスト色を白にする必要がありました。これで、colors.xmlに2つの色(#fffffと#000000)を設定し、テーブルのBackgroundResourceを黒に設定し、すべてのTextViewのTextColorを白に設定しました。ただし、表示されるのは、白いテキストが含まれていない黒い画面だけです。コードに間違いはありません。たぶんあなたはできる ;-)

public class ShowTableActivity extends Activity {

TableLayout t1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    t1 = createTable();
    fillTable();

    setContentView(t1);


}

public TableLayout createTable() {
    /** create table */
    TableLayout table = new TableLayout(this);
    table.setStretchAllColumns(true);
    table.setBackgroundResource(R.color.black);
    table.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT));

    /** title column/row */
    TableRow rowTitle = new TableRow(this);
    rowTitle.setGravity(Gravity.CENTER_HORIZONTAL);

    TextView title = new TextView(this);
    title.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    title.setGravity(Gravity.CENTER_HORIZONTAL);
    title.setText("Liganame");
    title.setTextSize(20);
    title.setTextColor(R.color.white);
    TableRow.LayoutParams params = new TableRow.LayoutParams();
    params.span = 9;
    rowTitle.addView(title, params);

    /** header row */
    TableRow rowHeader = new TableRow(this);
    rowHeader.setGravity(Gravity.CENTER_HORIZONTAL);
    TableRow.LayoutParams params1 = new TableRow.LayoutParams();
    params1.setMargins(5, 5, 5, 5);

    TextView rangHeader = new TextView(this);
    rangHeader.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));

    TextView mannschaftsnameHeader = new TextView(this);
    mannschaftsnameHeader.setLayoutParams(new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    TextView spieleHeader = new TextView(this);
    spieleHeader.setLayoutParams(new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    spieleHeader.setGravity(Gravity.CENTER_HORIZONTAL);
    spieleHeader.setText("Sp");
    spieleHeader.setTextSize(16);
    spieleHeader.setTextColor(R.color.white);

    TextView siegeHeader = new TextView(this);
    siegeHeader.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    siegeHeader.setGravity(Gravity.CENTER_HORIZONTAL);
    siegeHeader.setText("S");
    siegeHeader.setTextSize(16);
    siegeHeader.setTextColor(R.color.white);

    TextView unentschiedenHeader = new TextView(this);
    unentschiedenHeader.setLayoutParams(new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    unentschiedenHeader.setGravity(Gravity.CENTER_HORIZONTAL);
    unentschiedenHeader.setText("U");
    unentschiedenHeader.setTextSize(16);
    unentschiedenHeader.setTextColor(R.color.white);

    TextView niederlagenHeader = new TextView(this);
    niederlagenHeader.setLayoutParams(new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    niederlagenHeader.setGravity(Gravity.CENTER_HORIZONTAL);
    niederlagenHeader.setText("N");
    niederlagenHeader.setTextSize(16);
    niederlagenHeader.setTextColor(R.color.white);

    TextView toreHeader = new TextView(this);
    toreHeader.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    toreHeader.setGravity(Gravity.CENTER_HORIZONTAL);
    toreHeader.setText("Tore");
    toreHeader.setTextSize(16);
    toreHeader.setTextColor(R.color.white);
    TableRow.LayoutParams params2 = new TableRow.LayoutParams();
    params2.span = 3;

    TextView differenzHeader = new TextView(this);
    differenzHeader.setLayoutParams(new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    differenzHeader.setGravity(Gravity.CENTER_HORIZONTAL);
    differenzHeader.setText("Diff");
    differenzHeader.setTextSize(16);
    differenzHeader.setTextColor(R.color.white);

    TextView punkteHeader = new TextView(this);
    punkteHeader.setLayoutParams(new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    punkteHeader.setGravity(Gravity.CENTER_HORIZONTAL);
    punkteHeader.setText("Pkt");
    punkteHeader.setTextSize(16);
    punkteHeader.setTextColor(R.color.white);

    rowHeader.addView(rangHeader, new TableRow.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    rowHeader.addView(mannschaftsnameHeader, new TableRow.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    rowHeader.addView(spieleHeader, new TableRow.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    rowHeader.addView(siegeHeader, new TableRow.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    rowHeader.addView(unentschiedenHeader, new TableRow.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    rowHeader.addView(niederlagenHeader, new TableRow.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    rowHeader.addView(toreHeader, params2);
    rowHeader.addView(differenzHeader, new TableRow.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    rowHeader.addView(punkteHeader, new TableRow.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    table.addView(rowTitle);
    table.addView(rowHeader, params1);

    return table;
}

public void fillTable() {

    TableRow tr = new TableRow(this);

    TextView rang = new TextView(this);
    TextView mannschaftsname = new TextView(this);
    TextView spiele = new TextView(this);
    TextView siege = new TextView(this);
    TextView unentschieden = new TextView(this);
    TextView niederlagen = new TextView(this);
    TextView tore = new TextView(this);
    TextView doppelpunkt = new TextView(this);
    TextView gegentore = new TextView(this);
    TextView differenz = new TextView(this);
    TextView punkte = new TextView(this);

    rang.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    rang.setGravity(Gravity.CENTER_HORIZONTAL);
    rang.setText("0");
    rang.setTextColor(R.color.white);

    mannschaftsname.setLayoutParams(new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    mannschaftsname.setGravity(Gravity.CENTER_HORIZONTAL);
    mannschaftsname.setText("BBBBBBBBBB");
    mannschaftsname.setTextColor(R.color.white);

    spiele.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    spiele.setGravity(Gravity.CENTER_HORIZONTAL);
    spiele.setText("0");
    spiele.setTextColor(R.color.white);

    siege.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    siege.setGravity(Gravity.CENTER_HORIZONTAL);
    siege.setText("0");
    siege.setTextColor(R.color.white);

    unentschieden.setLayoutParams(new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    unentschieden.setGravity(Gravity.CENTER_HORIZONTAL);
    unentschieden.setText("0");
    unentschieden.setTextColor(R.color.white);

    niederlagen.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    niederlagen.setGravity(Gravity.CENTER_HORIZONTAL);
    niederlagen.setText("0");
    niederlagen.setTextColor(R.color.white);

    tore.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    tore.setGravity(Gravity.CENTER_HORIZONTAL);
    tore.setText("0");
    tore.setTextColor(R.color.white);

    doppelpunkt.setLayoutParams(new TableRow.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    doppelpunkt.setGravity(Gravity.CENTER_HORIZONTAL);
    doppelpunkt.setText(":");
    doppelpunkt.setTextColor(R.color.white);

    gegentore.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    gegentore.setGravity(Gravity.CENTER_HORIZONTAL);
    gegentore.setText("0");
    gegentore.setTextColor(R.color.white);

    differenz.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    differenz.setGravity(Gravity.CENTER_HORIZONTAL);
    differenz.setText("0");
    differenz.setTextColor(R.color.white);

    punkte.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    punkte.setGravity(Gravity.CENTER_HORIZONTAL);
    punkte.setText("0");
    punkte.setTextColor(R.color.white);

    tr.addView(rang, new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    tr.addView(mannschaftsname, new TableRow.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    tr.addView(spiele, new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    tr.addView(siege, new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    tr.addView(unentschieden, new TableRow.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    tr.addView(niederlagen, new TableRow.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    tr.addView(tore, new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    tr.addView(doppelpunkt, new TableRow.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    tr.addView(gegentore, new TableRow.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    tr.addView(differenz, new TableRow.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    tr.addView(punkte, new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));

    t1.addView(tr, new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));
  }
}
4

1 に答える 1

0

大規模な調査の結果、私の問題は解決しました。

R.color.whiteとR.color.blackを使用する代わりに、0xff000000(黒)と0xffffffff(白)を入力する必要があります。最初の2ffの後にカラーコードが始まるので、好きなものを選ぶことができます。

なぜあなたがこのようにしなければならないのか私に聞かないでください。多分誰か他の人がいつかここでそれを説明することができます。

于 2013-01-16T20:40:12.710 に答える