如何设置 Android ScrollView 渐隐边缘的颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2640877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:43:17  来源:igfitidea点击:

How to set the color of an Android ScrollView fading edge?

androidscrollviewfading

提问by Andrew Shooner

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.

我有一个白色背景的 Android 滚动视图。衰落边缘是一个白色的半透明渐变。我想把它改成黑色而不是白色。我在同一个项目中有一个 ListView,它的白色背景默认为黑色渐隐边缘,但我找不到设置的位置(如果有的话)。

回答by LEHO

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

如果您想要与背景不同的颜色渐隐边缘,则必须覆盖 ScrollView 的 getSolidColor() 方法。例如:

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

回答by digitarald

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.

只需android:background="@color/yourColor"<ScrollView>. 它会将阴影设置为给定的颜色。

回答by annelorayne

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);

回答by Joe

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

编辑:这不能回答问题,这是要求ScrollView. 此答案仅适用于AbsListView和 后代(包括ListView)。



Fading edge color is controlled by the android:cacheColorHintattribute.

渐隐边缘颜色由android:cacheColorHint属性控制。

E.g.:

例如:

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

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

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

将背景设置为白色,cacheColorHint用于绘制渐隐边缘颜色——在这种情况下,它将是黑色。

回答by David

You can use this:

你可以使用这个:

https://github.com/AndroidAlliance/EdgeEffectOverride

https://github.com/AndroidAlliance/EdgeEffectOverride

enter image description here

在此处输入图片说明

Simple clean and working perfect!

简单干净,工作完美!

回答by jqpubliq

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.Lightthe edge will be white. The default android.R.style.Themeand android.R.style.Theme.Blackwill have black fading edges. Themes also affect other attributes, so check out the attributes fully before you throw them in for one thing.

如果您不知道是什么改变了淡入淡出边缘的颜色,则可能是样式或主题的应用。android:theme="something"在活动中检查您的清单。如果主题来自该组,android.R.style.Theme.Light则边缘将为白色。默认设置android.R.style.Themeandroid.R.style.Theme.Black将有黑色渐隐边缘。主题也会影响其他属性,因此在将它们用于一件事之前,请完全检查这些属性。

回答by Douglas

Do this:

做这个:

  <ScrollView
    android:theme="@style/scrollUpdate"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

in values\styles put the style

在 values\styles 中放置样式

<style name="scrollUpdate">
    <item name="colorAccent">@color/yourcolor</item>
    <item name="android:color">@color/yourcolor</item>
    <item name="colorPrimary">@color/yourcolor</item>
    <item name="colorPrimaryDark">@color/yourcolor</item>
</style>

works to me tks!

对我有用 tks!