[英]ListView top highlight on scrolling
边框显示默认颜色(在我的Nexus S上为橙色),同时将ListView滚动到限制。 如何改变那种颜色?
我真的不知道如何解释它。 看看这张图:
那么,当ListView滚动到边框时如何更改高亮颜色? 使用主题或样式
解决方案是使用setOverscrollFooter(null)
和setOverscrollHeader(null)
。 文档在这里 !
您也可以直接在XML中设置它:
<ListView android:overScrollMode="never" />
或者指定页脚和标题:
<ListView
android:overscrollHeader="@null"
android:overscrollFooter="@null" />
注意:还有一个可能让您感兴趣的房产fadingEdge
。
启动API级别9支持“Overscroll”方法
最后我找到了解决方案。
setOverscrollFooter(null)
和setOverscrollHeader(null)
不起作用。 至少在2.3。*。 从* .xml设置属性也没有用。 setOverScrollMode(View.OVER_SCROLL_NEVER)
导致毛刺滚动。 至少在2.3。*。 唯一真正有效的解决方案是使用Java Reflection。 它甚至可以用丑陋的自定义三星列表视图和弹跳过度滚动效果。 这是一个片段:
@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
//onOverScrolled method must be overrided, or we will see the background of the listview when overscroll fast.
}
private void removeOverscrollEffect() {
try {
Class<?> superClass = getClass().getSuperclass().getSuperclass();
Field field = superClass.getDeclaredField("mEdgeGlowTop");
field.setAccessible(true);
Object edgeGlowTop = field.get(this);
if (edgeGlowTop != null) {
Class<? extends Object> edgeClass = edgeGlowTop.getClass();
Field edgeDrawable = edgeClass.getDeclaredField("mEdge");
edgeDrawable.setAccessible(true);
edgeDrawable.set(edgeGlowTop, new ColorDrawable(Color.TRANSPARENT));
Field glowDrawable = edgeClass.getDeclaredField("mGlow");
glowDrawable.setAccessible(true);
glowDrawable.set(edgeGlowTop, new ColorDrawable(Color.TRANSPARENT));
field.set(this, edgeGlowTop);
}
Field fieldBottom = superClass.getDeclaredField("mEdgeGlowBottom");
fieldBottom.setAccessible(true);
Object edgeGlowBottom = fieldBottom.get(this);
if (edgeGlowBottom != null) {
Class<? extends Object> edgeClassBottom = edgeGlowBottom.getClass();
Field edgeDrawableBottom = edgeClassBottom.getDeclaredField("mEdge");
edgeDrawableBottom.setAccessible(true);
edgeDrawableBottom.set(edgeGlowBottom, new ColorDrawable(Color.TRANSPARENT));
Field glowDrawableBottom = edgeClassBottom.getDeclaredField("mGlow");
glowDrawableBottom.setAccessible(true);
glowDrawableBottom.set(edgeGlowBottom, new ColorDrawable(Color.TRANSPARENT));
fieldBottom.set(this, edgeGlowBottom);
}
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
}
我希望这有帮助。
这是一篇关于ListView背景优化的好文章。
要解决此问题,您所要做的就是禁用缓存颜色提示优化,如果使用非纯色背景,或将提示设置为适当的纯色值。 您可以使用android:cacheColorHint属性从代码(请参阅setCacheColorHint(int))或最好从XML执行此操作。 要禁用优化,只需使用
transparent color #00000000
。 以下屏幕截图显示了一个包含android:cacheColorHint="#00000000"
在XML文件中使用它 -
<ListView ---
android:fadingEdge="none"
---</ListView>
编辑:
使用衰落边缘可能会引入明显的性能下降,并且只有在应用程序的可视化设计需要时才应使用。 要使用API级别14及更高级别请求淡化边缘,请使用android:requiresFadingEdge属性。
检查此API 链接
我使用了kord的答案,直到它停止在Lollipop工作,所以我改成了这个:
try {
Class<?> superClass = getClass().getSuperclass().getSuperclass();
Field field = superClass.getDeclaredField("mEdgeGlowTop");
field.setAccessible(true);
field.set(this, new NoEdgeEffect(getContext()));
Field fieldBottom = superClass.getDeclaredField("mEdgeGlowBottom");
fieldBottom.setAccessible(true);
fieldBottom.set(this, new NoEdgeEffect(getContext()));
} catch (Exception e) {
}
class NoEdgeEffect extends EdgeEffect
{
public NoEdgeEffect(Context context) {
super(context);
}
public boolean draw(Canvas canvas) {
// Do nothing
return false;
}
}
你可以使用android:listSelector =“#002234”。
在上面的值可以是你可以在互联网上轻松找到的任何颜色代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.