SikhWarrior
SikhWarrior

Reputation: 1087

ListView color change at bottom of screen

I have a weird problem, in my list view activity, I set the background colors of list items according to certain variables. Basically, the item will either be white, or grey, and blue if selected.

When I scroll the list (swiping down), the color of the list view item fades more and more as a row get closer to the bottom. At the bottom its lost all of its original color and I believe it is now transparent. So now, two different colored rows (white and grey) both look the same at the bottom. However, this doesn't happen to the blue colored items.

A quick google search led me to add

list.setVerticalFadingEdgeEnabled(false);

but this hasn't had an effect on the color change. Am I missing something here?

If needed, the code that sets the background color is as follows:

if (itemChecked.get(position)) {
                //If the row is selected, set blue
                row.setBackgroundColor(0x9934B5E4);
            } else if (!email.isRead()) {
                //If the email is unread, set white
                row.setBackgroundColor(Color.WHITE);
            } else {
                //Otherwise set grey.
                row.setBackgroundColor(0xd6d6d6);
            }

Any insight would be greatly appreciated, thanks!

EDIT: What it looks like.

Top of the screen. Top of the screen

Bottom of the screen At the bottom of the screen

Upvotes: 1

Views: 456

Answers (2)

Rick Falck
Rick Falck

Reputation: 1778

I saw this question recently. The answer given was that there is a default drawable being applied to the background of the entire ListView background that has a gradient from gray to white. Try giving the ListView a solid color for its background, like #ffffff.

All the similar questions say that this is the solution:

android:cacheColorHint="#000000"

Upvotes: 1

AndroidHacker
AndroidHacker

Reputation: 3596

U can try some thing like this ....

Undermentioned will put different color on either row .. This code is to be put on getView() method .. i.e method in your ArrayAdapterClass

if(position%2 == 0)
        {
            rowView.setBackgroundColor(context.getResources().getColor(R.color.list_dark));
        }
        else
        {
            rowView.setBackgroundColor(context.getResources().getColor(R.color.list_light));
        }

As far all rows is concerned simply do this ..

rowView.setBackgroundColor(context.getResources().getColor(R.color.list_dark));

U can implement this in your ArrayAdapterClass

Upvotes: 0

Related Questions