Rose18
Rose18

Reputation: 3160

Background color of a table row when it clicked

In my Android application I have a table. When user click a row, a new page is opened.

How can I set a background color for the row to make it easier for the user to see what he/she selected?

The color should only be visible for half a second or so, and be gone when it returns to the page.

Any suggestions are appreciated.

Cheers

Upvotes: 0

Views: 116

Answers (3)

Subramanian Ramsundaram
Subramanian Ramsundaram

Reputation: 1347

The Simplest way is, You can use android:listSelector in listview.

Upvotes: 0

Naveed Ali
Naveed Ali

Reputation: 2619

you can use....

TableRow tr = findViewById(R.id.tablerow);

when clicked. use following code in onClick() method...

tr.setBackgroundColor(Color.parseColor("#FF00FF"));

Upvotes: 0

Poutrathor
Poutrathor

Reputation: 2059

Usually I do that kind of thing using a selectors for focus and setting a drawable/layout as background of the table items.

For example i use this layout to make the background of a list in my current app :

 <LinearLayout

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/btn_nv"
    android:orientation="horizontal"
    android:paddingLeft="@dimen/padding_extra_small"
    android:paddingRight="@dimen/padding_extra_small" >

and the background drawable is the xml file named btn_nv (in drawable folder) whose content is below:

<?xml version="1.0" encoding="utf-8"?>

<item android:drawable="@drawable/btn_nv_normal" android:state_enabled="true" android:state_window_focused="false"/>
<item android:drawable="@drawable/btn_nv_normal_disable" android:state_enabled="false" android:state_window_focused="false"/>
<item android:drawable="@drawable/btn_nv_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/btn_nv_selected" android:state_enabled="true" android:state_focused="true"/>
<item android:drawable="@drawable/btn_nv_normal" android:state_enabled="true"/>
<item android:drawable="@drawable/btn_nv_normal_disable_focused" android:state_focused="true"/>
<item android:drawable="@drawable/btn_nv_normal_disable"/>

that allows change of background when user touch, pressed, etc...

Upvotes: 3

Related Questions