如何将 SwipeRefreshLayout 功能添加到 MaterialDrawer
How to add SwipeRefreshLayout functionality to MaterialDrawer
我想为已经提供此功能的 MaterialDrawer instance. Usually one would do this via the support libs SwipeRefreshLayout 的抽屉项目添加下拉刷新功能,但我找不到将其集成到 MaterialDrawer 中的好方法。
有一个名为 withDrawerLayout
的构建器选项,但此函数需要一个实际将 DrawerLayout 作为其根元素的布局 - 这显然对我的情况没有帮助。
有没有人有关于如何执行此操作的示例或想法?
低于 5.1.2 的 MaterialDrawer 版本无法做到这一点
对于您的用例,我实施了一项更改,允许您覆盖 material_drawer_recycler_view.xml
布局,并在其周围有一个额外的视图。
因此,要获得 SwipeRefreshLayout
,请执行以下操作:
- 更新到 MaterialDrawer v5.1.2
- 在您的项目中创建一个名为
material_drawer_recycler_view.xml
的布局
添加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" />
访问 SwipeRefreshLayout
SwipeRefreshLayout srl = (SwipeRefreshLayout) result.getSlider().findViewById(R.id.material_drawer_swipe_refresh);
现在您可以像使用其他任何东西一样使用它了SwipeRefreshLayout
我想为已经提供此功能的 MaterialDrawer instance. Usually one would do this via the support libs SwipeRefreshLayout 的抽屉项目添加下拉刷新功能,但我找不到将其集成到 MaterialDrawer 中的好方法。
有一个名为 withDrawerLayout
的构建器选项,但此函数需要一个实际将 DrawerLayout 作为其根元素的布局 - 这显然对我的情况没有帮助。
有没有人有关于如何执行此操作的示例或想法?
低于 5.1.2 的 MaterialDrawer 版本无法做到这一点
对于您的用例,我实施了一项更改,允许您覆盖 material_drawer_recycler_view.xml
布局,并在其周围有一个额外的视图。
因此,要获得 SwipeRefreshLayout
,请执行以下操作:
- 更新到 MaterialDrawer v5.1.2
- 在您的项目中创建一个名为
material_drawer_recycler_view.xml
的布局 添加
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" />
访问
SwipeRefreshLayout
SwipeRefreshLayout srl = (SwipeRefreshLayout) result.getSlider().findViewById(R.id.material_drawer_swipe_refresh);
现在您可以像使用其他任何东西一样使用它了SwipeRefreshLayout