Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9138485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:15:46+00:00 2026-06-17T09:15:46+00:00

I have programmatically created a TableLayout. Everything is working good. Except the background-colors and

  • 0

I have programmatically created a TableLayout. Everything is working good.
Except the background-colors and text-colors. I wanted the background-color of my TableLayout to be black and the text-color of each TextView should be white. Now I’ve set the two colors in my colors.xml (#fffff and #000000) and set the BackgroundResource for my table black and the TextColor for all my TextViews white. But the only thing showing is a black screen without any white text in it. I can’t see any mistake in my code. Maybe you can 😉

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));
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:15:46+00:00Added an answer on June 17, 2026 at 9:15 am

    Solved my problem after massive research:

    instead of using R.color.white and R.color.black, you have to put in 0xff000000 (black) and 0xffffffff (white). After the first 2 ff the color code starts, so you can pick any you want.

    Don’t ask me why you have to do it like this. Maybe somebody else can explain it here at some time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom tableview cell created programmatically that consists of: a background view
I have a UITextField which I created programmatically. This text field is used to
I have a TableLayout that is created programmatically in an Android project. I keep
I am working on UISearchBar which I have created programmatically. Below is what I
I have a tableLayout that is created programmatically, about 23 items are added to
Hi I have a UIButton that I created programmatically but unfortunately its not working.
I have my ipad code created programmatically not using nib.I converted my ipad app
HI, I am new to iphone development.I have created the tabbar programmatically and sets
I have a programmatically created UIScrollView, and I am creating it as the size
I have a tab bar controller that I have created programmatically, named TPastJourneyTabbar .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.