Manish
Manish

Reputation: 9

How to highlight a table row in foreground in android

I am creating a table with some table row in it and each tablerow contains three tabledata(textview). I am using the following color scheme.

TableLayoutBackgroundColor: White TableRowBackgroundColor:Black TableDataBackgroundColor(textview): white

setting marging for table row:

TableRow.LayoutParams params = new TableRow.LayoutParams();
params.setMargins(Constants.LEFT_MARGIN, Constants.TOP_MARGIN, Constants.RIGHT_MARGIN,Constants.BOTTOM_MARGIN);

Now the problem is when I highlight the tablerow using following code:

tr.setOnFocusChangeListener(new OnFocusChangeListener() {

                public void onFocusChange(View v, boolean hasFocus) {
                    // TODO Auto-generated method stub

                    if(hasFocus){                   
                    v.setBackgroundColor(Color.GREEN);  
                                            }
                    else
                    {
                        v.setBackgroundColor(Color.BLACK);
                    }

                }
            });

Only border of the table row is displayed. I want the highlighter over the complete row. Please suggest me how to do it.

Upvotes: 0

Views: 1453

Answers (2)

Mark Allison
Mark Allison

Reputation: 21909

Android manages this for you using the State List Drawables mechanism. I wrote a blog entry about how to use State List Drawables. The blog post specifically deals with applying these to a button, but the techniques are much the same for what you're trying to do.

Upvotes: 0

PedroAGSantos
PedroAGSantos

Reputation: 2346

I think that want you want is styles http://developer.android.com/guide/topics/ui/themes.html try to see if is that what you want hope it helped.

Example here with a button http://www.gersic.com/blog.php?id=56

Upvotes: 0

Related Questions