禁用滾動視圖ListView、ViewPager、ScrollView、HorizontalScrollView、WebView邊界顏色漸變
ListView、ViewPager、ScrollView、HorizontalScrollView、WebView等滾動試圖控件在高版本(一般是2.3及以上版本)上邊界會顯示一個漸變的顏色,下面是去掉這些顏色的方法:
1、ListView的父類AbsListView.java中有以下的一個方法:
@Override
public void setOverScrollMode(int mode) {
if (mode != OVER_SCROLL_NEVER) {
if (mEdgeGlowTop == null) {
Context context = getContext();
mEdgeGlowTop = new EdgeEffect(context);
mEdgeGlowBottom = new EdgeEffect(context);
}
} else {
mEdgeGlowTop = null;
mEdgeGlowBottom = null;
}
super.setOverScrollMode(mode);
}
在低版本上面沒有這個方法,就是這個mEdgeGlowTop、mEdgeGlowBottom這兩個貨導致的邊界漸變顏色。解決方法如下:你可以在自定義的ListView中調用,也可以在Activity或者Fragment的ListView屬性調用:
| try { Method method = getClass().getMethod("setOverScrollMode", int.class); Field field = getClass().getField("OVER_SCROLL_NEVER"); if(method != null && field != null){ method.invoke(this, field.getInt(View.class)); } } catch (Exception e) { e.printStackTrace(); } |
2、ScrollView、HorizontalScroll以及WebView的情況和ListView相同,處理方法也一樣。
3、ViewPager有些特殊,需要特殊處理,請參考我的這篇博客:http://www.cnblogs.com/xinye/p/3142704.html
