views:

733

answers:

4

I have an Android scrollview with a white background. The fading edge is a white translucent gradient. I would like to change it be black instead of white. I have a ListView in the same project with a white background that has a black fading edge by default, but I can't find where (if anywhere) that was set.

A: 

Fading edge color is controlled by the android:cacheColorHint attribute.

E.g.:

<ScrollView android:cacheColorHint="#ff000000" android:background="#ffffffff" />

will set the background to white, and the cacheColorHint is used to draw the fading edge color -- in this case, it would be black.

Joe
I have tried this attribute, but it does not work. It appears that this attribute/method only apply to [AbsListView](http://developer.android.com/intl/fr/reference/android/widget/AbsListView.html#setCacheColorHint%28int%29).
Andrew Shooner
What about http://developer.android.com/intl/zh-CN/reference/android/view/View.html#setDrawingCacheBackgroundColor%28int%29 ?
Joe
A: 

If you don't know what changed the color of your fading edge, it was probably the application of a style or theme. Check your manifest for android:theme="something" in an Activity. If the theme is from the group android.R.style.Theme.Light the edge will be white. The default android.R.style.Theme and android.R.style.Theme.Black will have black fading edges. Themes also affect other attributes, so check out the attributes fully before you throw them in for one thing.

jqpubliq
Andrew Shooner
The comment above it: `<!-- Variant of the default (dark) theme with no title bar -->`So, you are using the dark theme which includes black fading edges.you want `Theme.Light.NoTitleBar`
jqpubliq
I have changed to this theme, and it has not affected the fading edge color.
Andrew Shooner
try setting the style on the list itself just to make sure it's not being overridden in a tighter scope
jqpubliq
+1  A: 

Just found it out by trial and error.

Simply set android:background="@color/yourColor" for the <ScrollView>. It will set the shadow to the given colour.

digitarald
Yep, devilishly simple. As you'd imagine, you then just have to set the scrollview immediate child to the background you want. Thanks!
Andrew Shooner
A: 

If you want a different color fading edge than the background, you have to override the ScrollView's getSolidColor() method. For example:

@Override
public int getSolidColor() {
    return Color.rgb(0x30, 0x30, 0x30);
}
LEHO