Skip to content Skip to sidebar Skip to footer

How Do I Change The Background Color For A Column Of My Android App

My Android app has a table with seven columns. I'd like to change the background color of these columns when the content in the table is updated. How do I specify columns in the

Solution 1:

To give your textviews equal width and therefore fix your higlighting issue you should look at the layout_weight property

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="#CDCDCD"android:orientation="vertical"><TableLayoutandroid:id="@+id/tableLayout1"android:layout_width="match_parent"android:layout_height="wrap_content"><TableRowandroid:id="@+id/tableRow1"android:layout_width="0dip"android:layout_height="wrap_content"android:layout_weight="0.5"><TextViewandroid:text="100"android:id="@+id/textView2"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_column="1"></TextView></TableRow><TableRowandroid:id="@+id/tableRow2"android:layout_width="0dip"android:layout_height="wrap_content"android:layout_weight="0.5"><TextViewandroid:text="100"android:id="@+id/textView11"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_column="1"></TextView></TableRow></TableLayout></LinearLayout>

Now I'm not at my development PC so can't verify this (and fix my formatting), but it should work I'll check it later.

Solution 2:

Maybe not the prettiest solution but you could change the background color of all the TextViews in the column.

TextViewtextview2= (TextView) findViewById(R.id.textView2);
TextViewtextview11= (TextView) findViewById(R.id.textView11);
textview2.setBackgroundColor(Color.RED);
textview11.setBackgroundColor(Color.RED);

Solution 3:

I ended up using a series of nested linear layouts, a full-screen horizonal one with evenly spaced vertical ones for the columns. If I then set the TextView background to transparent, I can change the entire column background by setting the background of the column's LinearLayout.

Post a Comment for "How Do I Change The Background Color For A Column Of My Android App"