android:如何为TableRow分配默认主题颜色
我有一个表,可以在其中动态添加行。默认情况下,单击一行时不会发生任何更改,因此用户无法收到看到哪一行的通知。我想为行的 onClick 事件设置默认主题背景颜色。这样做的主要目的是将其选择与应用程序的其他组件相匹配。
编辑 : 为了使其更简单易懂,以下是具体场景: 我有一个表格布局,里面有一个表格布局。我动态添加包含 3 个 TextView 的 TableRow。 选择选项卡时,其颜色从灰色变为白色。我希望在选定的行上完成相同的颜色设置。 在任何情况下,我想确保无论选项卡选择的颜色是什么,相同的颜色都应用于行选择。
这就是我的确切要求,我正在寻找过去两天的解决方案。但找不到合适的东西。 目前我正在通过以下方式更改行选择:
currSelectedRow.setBackgroundResource(android.R.drawable.divider_horizontal_bright); // .list_selector_background);
“list_selector_background”占据行下方的长度,并且在选择下一行时,spcae不会被排除。因此,行与行之间都留有空格。同样,我也尝试过使用“tab....”,这也导致了与 list_selector 几乎相同的结果。目前刚刚使用“divider_horizontal_bright”来了解选择哪一行。但没有得到我的解决方案。
我希望将选项卡的选定背景颜色应用于行的背景颜色。
如何获取此信息并设置所选行的颜色?
I have a table in which I add rows dynamically. By default when a row is clicked, nothing is changed so user can't get notification of which row is seected. I want to set the default theme background color for onClick event of row. The main purpose of this is to match its selection with other components of the application.
EDIT :
To make it simpler and easy to understand, here's the exact scenario :
I have a tablayout, that has a tablelayout in it. I am adding TableRow's dynamically that contians 3 TextView's.
On selecting a tab, its color changes fron Gray to Whitish. I want the same color setting to be done on my row selected.
In any situation, I want to make sure that whatever is the color for tab selection that same color is applied to row selection.
This is what my exact requirement is and am looking for a solution from last 2 days. But can't find anything proper.
At present I am changinf row selection by :
currSelectedRow.setBackgroundResource(android.R.drawable.divider_horizontal_bright); // .list_selector_background);
"list_selector_background" occupies that much length below the row and on next row selection that spcae is not evned out. So spaces are left between rows here and there. Similarly, I also tried with "tab...." that also caused the almost same results as list_selector. At present have just used "divider_horizontal_bright" to get the idea of which row is selected. But doesn't get my solution.
I want the selectedtion background colro of tab to be applied to background color of row.
How do I get this info and set the color of the row selected ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢@克里希纳,
但这对我来说没有成功。我在表行上使用 onFocusListener 和 onClick 实现,效果非常好。我想使用选择器,但我想..
Thanks @Krishna,
But that didn't work out for me. I implemented using onFocusListener and onClick on Table Row and that worked out perfectly. I wanted to use selector, but I guess ..