android:将Tab的单击颜色设置为TableRow的背景颜色
我有一个选项卡布局。我有一个带有动态添加行的表格布局。 当选择/单击 TableRow 时,我想将其背景颜色设置为选项卡的按下或单击颜色。
我不想设置任何静态颜色,但想使用默认主题颜色。如何获取 Tablayout 的颜色信息?
如何处理选项卡的左侧和右侧?这就是我在将 tab_background.xml 设置为所有选项卡的 backgroundRsourse 之后得到的结果:
左侧,两张图片都没有任何设置,但左右角都是平滑的。 在右侧,两个图像都带有设置,请看到所选选项卡的角只是一个正方形,它们应该像没有任何设置的选项卡一样被圆化或平滑。 看来我必须使用 tab_selected_bar_right 和 tab_selected_bar_left 。我已将它们复制到我的绘图中,但不知道如何使用它们。对 @mudit 提供的下面的 xml 进行哪些设置。
请指导我。非常感谢任何帮助。我很急。
谢谢
I have a TabLayout. In that I have a tablelayout with dynamically added rows.
When a TableRow is selected/clicked I want to set its background color to the Pressing or Clicked color of Tab.
I don't want to set any static color but want to use the default theme color. How to get the color info of Tablayout ?
How to handle the left and right side of the tabs ? This is what I get begore and after setting the tab_background.xml as th backgroundRsourse for all tabs :
On the left hand side, both the images are without any settings, but the right and left corners are smooth.
On right hand side, both images are with setings, see the corners of selected tabs are just a square, they should be rounded off or smoth like the ones without any settings.
It seems I got to use tab_selected_bar_right and tab_selected_bar_left. I have copied them to my drawable, but can't make out how do I use them. What settings to give int the xml below provided by @mudit.
Please guide me. Any help is highly appreciated. I am in a hurry.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的java文件中添加选项卡后添加此代码:(
我只添加2个选项卡,如果您有更多选项卡,您可以添加此代码)
代码tab_background.xml:(
将其放入drawable文件夹中)
Add this code after adding the tabs in your java file:
( I am adding only 2 tabs, you can add this if you have more tabs)
Code tab_background.xml:
(put this in drawable folder)
我解决了这个问题。我很抱歉没有早点提到这一点。抱歉,我刚刚错过了。
@Yugandhar,感谢您的关注。
Am solved with this issue. I apology for not mentioning it earlier. Sorry, I just missed out.
@Yugandhar, Thanks for your interest.