Skip to content

悬浮搜索:快速实现搜索功能,支持搜索建议、语音搜索、分类检索以及个性化设置。

License

Notifications You must be signed in to change notification settings

zappu9x/FloatingSearchView-1

Repository files navigation

FloatingSearch

Android Arsenal Platform API OSSLab

可以显示搜索建议和搜索历史的悬浮搜索框,你可以在基于该组件快速实现语音搜索、分类检索以及个性化设置。

JellyRefresh

使用方法

首先,你需要导入模块项目或者添加依赖类库:

dependencies {
    compile 'online.osslab:FloatingSearch:1.0.0'
}

布局文件

<online.osslab.FloatingSearchView
            android:id="@+id/floating_search_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:dismissOnOutsideTouch="true"
            app:leftActionMode="showHamburger"
            app:searchBarMarginLeft="@dimen/search_view_inset"
            app:searchBarMarginRight="@dimen/search_view_inset"
            app:searchBarMarginTop="@dimen/search_view_inset"
            app:searchHint="搜索..."
            app:searchMenu="@menu/menu"
            app:showSearchKey="false" />

回调函数

SearchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {
              @Override
              public void onSearchTextChanged(String oldQuery, final String newQuery) {

                  //get suggestions based on newQuery

                  //pass them on to the search view
                  SearchView.swapSuggestions(newSuggestions);
              }
          });
快捷操作
   app:leftActionMode="[options]"
showHamburger
showSearch
showHome
none
  • 监听 汉堡菜单 事件:
 searchView.setOnLeftMenuClickListener(
        new FloatingSearchView.OnLeftMenuClickListener() { ...} );
  • 监听 返回按钮 事件:
  searchView.setOnHomeActionClickListener(
         new FloatingSearchView.OnHomeActionClickListener() { ... });
搜索菜单
    app:searchMenu="@menu/menu_main"

设置菜单项显示方式:app:showAsAction="[options]"

never 隐藏选项
ifRoom 满足条件显示: 1. 搜索框未获得焦点; 2. 搜索框有足够空间;
always 始终显示
  • 监听 菜单按钮 事件:
   searchView.setOnMenuItemClickListener(new FloatingSearchView.OnMenuItemClickListener() {
      @Override
      public void onMenuItemSelected(MenuItem item) {

      }
   });

搜索建议

首先,你需要实现 SearchSuggestion 接口。

  • 回调函数(可选):
   searchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() {
            @Override
            public void onBindSuggestion(IconImageView leftIcon, BodyTextView bodyText, SearchSuggestion item, int itemPosition) {

                       //here you can set some attributes for the suggestion's left icon and text. For example,
                       //you can choose your favorite image-loading library for setting the left icon's image.
            }

        });

个性设置

   <style name="SearchView">
           <item name="backgroundColor"></item>
           <item name="viewTextColor"></item>
           <item name="hintTextColor"></item>
           <item name="dividerColor"></item>
           <item name="clearBtnColor"></item>
           <item name="leftActionColor"></item>
           <item name="menuItemIconColor"></item>
           <item name="suggestionRightIconColor"></item>
           <item name="actionMenuOverflowColor"></item>
    </style>

关于作者

许可协议

Copyright 2015 Arlib

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

悬浮搜索:快速实现搜索功能,支持搜索建议、语音搜索、分类检索以及个性化设置。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages