android:如何为TableRow分配默认主题颜色

发布于 2024-11-09 11:47:36 字数 713 浏览 0 评论 0原文

我有一个表,可以在其中动态添加行。默认情况下,单击一行时不会发生任何更改,因此用户无法收到看到哪一行的通知。我想为行的 onClick 事件设置默认主题背景颜色。这样做的主要目的是将其选择与应用程序的其他组件相匹配。

编辑 : 为了使其更简单易懂,以下是具体场景: 我有一个表格布局,里面有一个表格布局。我动态添加包含 3 个 TextView 的 TableRow。 选择选项卡时,其颜色从灰色变为白色。我希望在选定的行上完成相同的颜色设置。 在任何情况下,我想确保无论选项卡选择的颜色是什么,相同的颜色都应用于行选择。

这就是我的确切要求,我正在寻找过去两天的解决方案。但找不到合适的东西。 目前我正在通过以下方式更改行选择:

currSelectedRow.setBackgroundResource(android.R.drawable.divider_horizo​​ntal_bright); // .list_selector_background);

“list_selector_background”占据行下方的长度,并且在选择下一行时,sp​​cae不会被排除。因此,行与行之间都留有空格。同样,我也尝试过使用“tab....”,这也导致了与 list_selector 几乎相同的结果。目前刚刚使用“divider_horizo​​ntal_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由范儿 2024-11-16 11:47:36

谢谢@克里希纳,
但这对我来说没有成功。我在表行上使用 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 ..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文