As my project requirement i have to highlight the table row on onClick. There is any way to do this? Or please suggest me the alternative?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
Within the onclicklistener add:
Where tr1 is your tablerow. (you will need to make the tablerow final for it to work).
If you want to use the stock on click highlight like you get with a generic ListView, you want to set the background of each row to be
android:background="@android:drawable/list_selector_background"
Here is an example:
Then in code,
And you should get a highlight-able row just like in a ListView...
EDIT: Above will give you the default theme's list background selector. If you want the more generic selector (like the material design selector when the user touches a row) use this:
Also this applies to more than just TableRows. You should be able to do this on almost any generic widget with an onClickListener attached (TextViews, Buttons, etc).
Even I was facing the same problem with the help of salil pandit answer made a little change to it and that works for me
This is
TableRow
in xml:This is
selector.xml
inres\drawable
folder