在百度中无意发现
package com.bang.myswiprefreshlayout;
importandroid.content.Context;
importandroid.support.v4.widget.SwipeRefreshLayout;
importandroid.util.AttributeSet;
importandroid.view.View;
importjava.lang.reflect.Field;
importjava.lang.reflect.Method;
public classAutoSwipeRefreshLayout extends SwipeRefreshLayout {
public AutoSwipeRefreshLayout(Contextcontext) {
super(context);
}
public AutoSwipeRefreshLayout(Contextcontext, AttributeSet attrs) {
super(context, attrs);
autoSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright);//设置小圆圈颜色(可同时设置多种)
}
/**
* 自动刷新
*/
public void autoRefresh() {
try {
Field mCircleView =SwipeRefreshLayout.class.getDeclaredField("mCircleView");
mCircleView.setAccessible(true);
View progress = (View)mCircleView.get(this);
progress.setVisibility(VISIBLE);
Method setRefreshing =SwipeRefreshLayout.class.getDeclaredMethod("setRefreshing",boolean.class, boolean.class);
setRefreshing.setAccessible(true);
setRefreshing.invoke(this, true,true);
} catch (Exception e) {
e.printStackTrace();
}
}
}