Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a custom SwipeRefreshLayout Indicator?

How would I go about making a custom indicator that would use a drawable object with a custom animation for the SwipeRefreshLayout?

I looked over the source code for SwipeRefreshLayout and I noticed the CircleImageView object was private.

Is there anyway to modify the ImageView?

like image 982
AndyRoid Avatar asked Oct 16 '15 00:10

AndyRoid


2 Answers

You can change the drawable via reflection, not sure how good this idea is. Something like :

mSwipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.your_swiperefresh_id);
try {
    Field f = mSwipeRefreshLayout.getClass().getDeclaredField("mCircleView");
    f.setAccessible(true);
    ImageView img = (ImageView)f.get(mSwipeRefreshLayout);
    img.setImageResource(R.drawable.your_drawable_file);
} catch (NoSuchFieldException e) {
    e.printStackTrace();
} catch (IllegalAccessException e) {
    e.printStackTrace();
}
like image 64
abhishesh Avatar answered Sep 22 '22 23:09

abhishesh


Try https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh. Modify System widget is troublesome.

like image 32
tiny sunlight Avatar answered Sep 20 '22 23:09

tiny sunlight