How to add Backgroung Image to Tablelayout in Android?
-
06-12-2019 - |
Question
I have TableLayout in my project which contains 6 TableRow layouts. Each TableRow layout has 7 TextViews in it. I want to set a background image to this TableLayout which is currently displaying 42 TextViews. I also had set some background color to each TextView. I tried this
mDateSelectionBar.setBackgroundResource(resid);
But it is not showing up my Image. However, If I do this for my 42 TextViews..
TextView.setBackgroundResource(0);
Then my Image is visible. But I want to display TableLayout background Image as well as background color of each TextView. How can I do this? Please Help! Thanks :D
Solution
The issue is that the background of the individual cells in a table layout is drawn over the overall layout background. If you remove the background of the cell, then the overall background is visible. If you need to display the background of the table as well as some colouring of the cells, consider setting the alpha channel of the cell background colour to less than 100%, e.g. 0.8 or something.
When you set the colour for your cells, use #ARGB syntax, e.g.
setBackgroundColour(Color.argb(192, 255, 0, 0));