如何设置Android Scrollview褪色边缘的颜色?
-
27-09-2019 - |
题
我有一个带有白色背景的Android Scrollview。褪色的边缘是白色半透明梯度。我想改变它是黑色而不是白色。我在同一项目中有一个列表视图,其白色背景默认情况下具有黑色褪色边缘,但是我找不到设置的(如果在任何地方)的位置。
解决方案
刚刚通过反复试验发现了它。
简单地设置 android:background="@color/yourColor"
为了 <ScrollView>
. 。它将将阴影设置为给定的颜色。
其他提示
如果您想要与背景不同的颜色褪色边缘,则必须覆盖Scrollview的getolidColor()方法。例如:
@Override
public int getSolidColor() {
return Color.rgb(0x30, 0x30, 0x30);
}
您可以使用:
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);
编辑: :这没有回答这个问题 ScrollView
. 。这个答案只能使用 AbsListView
和后代(包括 ListView
).
褪色的边缘颜色由 android:cacheColorHint
属性。
例如:
<ScrollView android:cacheColorHint="#ff000000" android:background="#ffffffff" />
将把背景设置为白色, cacheColorHint
用于绘制褪色的边缘颜色 - 在这种情况下,它将是黑色的。
如果您不知道是什么改变了褪色边缘的颜色,那可能是样式或主题的应用。检查您的清单 android:theme="something"
在活动中。如果主题来自小组 android.R.style.Theme.Light
边缘将是白色的。默认值 android.R.style.Theme
和 android.R.style.Theme.Black
将有黑色褪色的边缘。主题还会影响其他属性,因此在将它们扔进一件事之前,请全面查看属性。
做这个:
<ScrollView
android:theme="@style/scrollUpdate"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
在价值样式中放置样式
<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>
对我有用!