How to set the color of an Android ScrollView fadi

2019-01-16 15:53发布

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.

7条回答
啃猪蹄的小仙女
2楼-- · 2019-01-16 16:27

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.

查看更多
我只想做你的唯一
3楼-- · 2019-01-16 16:39

EDIT: this does not answer the question, which was asking for ScrollView. This answer only works on AbsListView and descendants (including ListView).


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.

查看更多
别忘想泡老子
4楼-- · 2019-01-16 16:43

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);
}
查看更多
The star\"
5楼-- · 2019-01-16 16:43

You can use this:

https://github.com/AndroidAlliance/EdgeEffectOverride

enter image description here

Simple clean and working perfect!

查看更多
对你真心纯属浪费
6楼-- · 2019-01-16 16:44

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.

查看更多
Evening l夕情丶
7楼-- · 2019-01-16 16:47

You can use:

    final int glowDrawableId = context.getResources().getIdentifier("overscroll_glow",
            "drawable", "android");
    final Drawable androidGlow = context.getResources().getDrawable(glowDrawableId);
    androidGlow.setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);

    int edgeDrawableId = context.getResources().getIdentifier("overscroll_edge", "drawable",
            "android");
    final Drawable androidEdge = context.getResources().getDrawable(edgeDrawableId);
    androidEdge.setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
查看更多
登录 后发表回答