evrencoskun / TableView

TableView is a powerful Android library for displaying complex data structures and rendering tabular data composed of rows, columns and cells.
MIT License
3.14k stars 459 forks source link

Background color for headers overwritten by cell color definition #243

Open tva-TIS opened 5 years ago

tva-TIS commented 5 years ago

I don't really know how far this is considered an issue by the author, but I'm gonna leave this here for anyone that struggles with setting the unselected header color too as I didn't found this documented anywhere else.

Problem Setting the background on the row header and column header layouts within their xmls is currently useless, as it is overwritten by the TableView frame definitions of unselected_color. This doesn't occur for the corner layout.

Workaround/Solution The sample app solves the issue by setting the backgroundColor manually to the header background color within setSelected like this:

if (p_nSelectionState == SelectionState.SELECTED) {
    nBackgroundColorId = R.color.selected_background_color;
    nForegroundColorId = R.color.selected_text_color;
} else if (p_nSelectionState == SelectionState.UNSELECTED) {
    nBackgroundColorId = R.color.unselected_header_background_color;
    nForegroundColorId = R.color.unselected_text_color;
}

I did it the other way around, as I needed to set the color on cells anyway depending on their content and defined the unselected_color attribute of the TableView as the colors the headers should have.

Change Suggestion I would suggest limiting the unselected_color attribute to content cells. Maybe it would be even useful to add one or two (row, column) additional attributes to set the header color within the xml of the table view.

NainalChauhan commented 4 years ago

Hi, Where I have to put below code to change the background color?

if (p_nSelectionState == SelectionState.SELECTED) { nBackgroundColorId = R.color.selected_background_color; nForegroundColorId = R.color.selected_text_color; } else if (p_nSelectionState == SelectionState.UNSELECTED) { nBackgroundColorId = R.color.unselected_header_background_color; nForegroundColorId = R.color.unselected_text_color; }

evrencoskun commented 4 years ago

@NainalChauhan in your view holder. Please check out the TableViewSample repo.