android toolbar 搜索框,SearchView配合RecyclerView实现分页搜索过滤关键字

在日常开发中,我们会遇到一种需求,就是通过输入关键字快速的查询当前列表中的数据并进行过滤显示。(感觉好难用文字描述这个功能啊·····),在网上找了一些资料也没有类似的文章,只好自己变尝试变查资料,用了几个小时的时间终于搞出来了。

OK,看图:

6a07e960bc64

1.gif

组件准备

1.SearchView:SearchView是Android原生的搜索框控件,它提供了一个用户界面,用于用户搜索查询。

SearchView默认是展示一个search的icon,点击icon展开搜索框,如果你想让搜索框默认就展开,可以通过setIconifiedByDefault(false);实现。

2.XRecyclerView: github地址

这个组件主要是对RecyclerView的封装,主要完成了下拉刷新、上拉加载更多、RecyclerView头部。

关于这个组件的详解,请参考这篇文章:文章地址

开始布局

现在先进行布局:

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:id="@+id/main_content"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/window_background"

android:fitsSystemWindows="true"

android:focusable="true"

android:focusableInTouchMode="true">

android:id="@+id/appbar"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@color/app_main_color"

android:minHeight="?attr/actionBarSize"

app:layout_scrollFlags="scroll"

app:popupTheme="@style/ThemeOverlay.AppCompat.Light"

app:theme="@style/ThemeOverlay.AppCompat.ActionBar"

app:title="@string/location_detail"

app:titleTextColor="@color/white" />

android:id="@+id/searchView"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="@dimen/spacing_small"

android:iconifiedByDefault="false"

android:queryHint="@string/search_hint"

android:textColor="@color/white"

/>

android:id="@

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值