Strayer
Strayer

Reputation: 3120

How to add SwipeRefreshLayout functionality to MaterialDrawer

I want to add a pull-to-refresh functionality to the drawer items of a MaterialDrawer instance. Usually one would do this via the support libs SwipeRefreshLayout that already provides this functionality, but I couldn't find a nice way to integrate this into MaterialDrawer.

There is a builder option called withDrawerLayout, but this function expects a layout that actually has a DrawerLayout as its root element - this obviously won't help in my case.

Does anyone have an example or an idea on how to do this?

Upvotes: 0

Views: 147

Answers (1)

mikepenz
mikepenz

Reputation: 12858

This is not possible with versions lower than 5.1.2 of the MaterialDrawer

For your use case I have implemented a change which allows you to overwrite the material_drawer_recycler_view.xml layout, and to have a an additional view around it.

So to get the SwipeRefreshLayout do the following:

  1. update to the MaterialDrawer v5.1.2
  2. create a layout called material_drawer_recycler_view.xml in your project
  3. add the SwipeRefreshLayout

    <android.support.v7.widget.RecyclerView
        android:id="@+id/material_drawer_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical" />
    

  4. access the SwipeRefreshLayout

    SwipeRefreshLayout srl = (SwipeRefreshLayout) result.getSlider().findViewById(R.id.material_drawer_swipe_refresh);

Now you are able to use it as any other SwipeRefreshLayout

Upvotes: 1

Related Questions