Convert Figma logo to code with AI

arimorty logofloatingsearchview

A search view that implements a floating search bar also known as persistent search

3,542
668
3,542
78

Top Related Projects

Material Design Search Bar for Android

2,232

Material You Search component for Android, SearchView

Android Search View based on Material design guidelines.

A clone of the Google Now/Maps/Play persistent search bar

Quick Overview

FloatingSearchView is an Android library that provides a floating search widget with search suggestions and custom search actions. It offers a Material Design-inspired interface for implementing search functionality in Android applications, with smooth animations and customizable features.

Pros

  • Easy integration with minimal setup required
  • Highly customizable appearance and behavior
  • Smooth animations and transitions
  • Support for search suggestions and custom actions

Cons

  • Limited documentation and examples
  • May require additional work to integrate with complex data sources
  • Some reported issues with compatibility on older Android versions
  • Infrequent updates and maintenance

Code Examples

  1. Basic setup of FloatingSearchView:
val searchView = findViewById<FloatingSearchView>(R.id.floating_search_view)
searchView.setOnQueryChangeListener { oldQuery, newQuery ->
    // Handle query changes
}
  1. Adding search suggestions:
searchView.setOnSearchListener(object : FloatingSearchView.OnSearchListener {
    override fun onSuggestionClicked(searchSuggestion: SearchSuggestion) {
        // Handle suggestion click
    }

    override fun onSearchAction(currentQuery: String) {
        // Perform search action
    }
})

searchView.swapSuggestions(listOf(
    CustomSearchSuggestion("Suggestion 1"),
    CustomSearchSuggestion("Suggestion 2")
))
  1. Customizing appearance:
searchView.setBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary))
searchView.setViewTextColor(ContextCompat.getColor(this, R.color.textColorPrimary))
searchView.setHintTextColor(ContextCompat.getColor(this, R.color.textColorHint))

Getting Started

  1. Add the dependency to your app's build.gradle file:
dependencies {
    implementation 'com.github.arimorty:floatingsearchview:2.1.1'
}
  1. Add the FloatingSearchView to your layout XML:
<com.arlib.floatingsearchview.FloatingSearchView
    android:id="@+id/floating_search_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:floatingSearch_searchHint="Search..."
    app:floatingSearch_suggestionsListAnimDuration="250"
    app:floatingSearch_showSearchKey="false"
    app:floatingSearch_leftActionMode="showHamburger"
    app:floatingSearch_menu="@menu/menu_search"/>
  1. Initialize and customize the FloatingSearchView in your Activity or Fragment:
val searchView = findViewById<FloatingSearchView>(R.id.floating_search_view)
searchView.setOnQueryChangeListener { oldQuery, newQuery ->
    // Handle query changes
}
searchView.setOnSearchListener(object : FloatingSearchView.OnSearchListener {
    override fun onSuggestionClicked(searchSuggestion: SearchSuggestion) {
        // Handle suggestion click
    }

    override fun onSearchAction(currentQuery: String) {
        // Perform search action
    }
})

Competitor Comparisons

Material Design Search Bar for Android

Pros of MaterialSearchBar

  • Simpler implementation with fewer dependencies
  • Includes built-in speech recognition support
  • More customizable appearance with XML attributes

Cons of MaterialSearchBar

  • Less extensive documentation and examples
  • Fewer advanced features like custom suggestions
  • Not as actively maintained (last update over 2 years ago)

Code Comparison

FloatingSearchView:

mSearchView = findViewById(R.id.floating_search_view);
mSearchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {
    @Override
    public void onSearchTextChanged(String oldQuery, String newQuery) {
        // Handle query change
    }
});

MaterialSearchBar:

MaterialSearchBar searchBar = findViewById(R.id.searchBar);
searchBar.setOnSearchActionListener(new MaterialSearchBar.OnSearchActionListener() {
    @Override
    public void onSearchStateChanged(boolean enabled) {
        // Handle search state change
    }
});

Both libraries offer similar basic functionality for implementing a search bar in Android applications. FloatingSearchView provides more advanced features and customization options, making it suitable for complex search implementations. MaterialSearchBar, on the other hand, offers a simpler approach with built-in speech recognition, which can be beneficial for projects requiring voice input. The choice between the two depends on the specific requirements of your project and the level of customization needed.

2,232

Material You Search component for Android, SearchView

Pros of Search

  • More comprehensive search functionality, including voice search and persistent search history
  • Supports multiple search styles (e.g., toolbar, floating, persistent)
  • Regular updates and active maintenance

Cons of Search

  • Larger library size, potentially impacting app performance
  • Steeper learning curve due to more complex implementation

Code Comparison

FloatingSearchView:

<com.arlib.floatingsearchview.FloatingSearchView
    android:id="@+id/floating_search_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:floatingSearch_searchHint="Search..."
    app:floatingSearch_suggestionsListAnimDuration="250"
    app:floatingSearch_showSearchKey="false"
    app:floatingSearch_leftActionMode="showHamburger"
    app:floatingSearch_menu="@menu/menu_main" />

Search:

<com.lapism.search.widget.SearchView
    android:id="@+id/search_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:search_style="toolbar"
    app:search_theme="light"
    app:search_divider="true"
    app:search_voice="true"
    app:search_hint="Search..." />

Both libraries offer customizable search views for Android applications. FloatingSearchView focuses on a floating search bar design, while Search provides more versatile search options and styles. The code comparison shows that Search offers additional attributes for customization, such as search style and voice search support, which are not present in FloatingSearchView's implementation.

Android Search View based on Material design guidelines.

Pros of MaterialSearchView

  • Simpler implementation with fewer dependencies
  • Easier to customize and integrate into existing layouts
  • Supports voice search functionality out of the box

Cons of MaterialSearchView

  • Less visually appealing default styling compared to FloatingSearchView
  • Fewer built-in features and animations
  • Less active maintenance and community support

Code Comparison

FloatingSearchView:

<com.arlib.floatingsearchview.FloatingSearchView
    android:id="@+id/floating_search_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:floatingSearch_searchHint="Search..."
    app:floatingSearch_suggestionsListAnimDuration="250"
    app:floatingSearch_showSearchKey="false"
    app:floatingSearch_leftActionMode="showHamburger"
    app:floatingSearch_menu="@menu/menu_search_view"
    app:floatingSearch_close_search_on_keyboard_dismiss="true"/>

MaterialSearchView:

<br.com.mauker.materialsearchview.MaterialSearchView
    android:id="@+id/search_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

The code comparison shows that MaterialSearchView has a simpler XML implementation, while FloatingSearchView offers more customization options directly in the layout file. FloatingSearchView provides more built-in attributes for styling and behavior, whereas MaterialSearchView relies more on programmatic customization.

A clone of the Google Now/Maps/Play persistent search bar

Pros of PersistentSearch

  • Offers a more native Android look and feel
  • Provides smoother animations and transitions
  • Integrates well with the Android action bar

Cons of PersistentSearch

  • Less customizable in terms of appearance
  • Limited documentation and examples
  • Fewer features compared to FloatingSearchView

Code Comparison

PersistentSearch:

SearchBox searchBox = (SearchBox) findViewById(R.id.searchbox);
searchBox.enableVoiceRecognition(this);
searchBox.setLogoText("Search");

FloatingSearchView:

mSearchView = (FloatingSearchView) findViewById(R.id.floating_search_view);
mSearchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {
    @Override
    public void onSearchTextChanged(String oldQuery, String newQuery) {
        // Handle query change
    }
});

PersistentSearch provides a simpler setup with fewer lines of code, while FloatingSearchView offers more customization options and event listeners. FloatingSearchView has more extensive documentation and a larger community, making it easier to implement and troubleshoot. However, PersistentSearch may be preferred for projects requiring a more native Android appearance and smoother animations.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Floating Search View Android Arsenal

An implementation of a floating search box with search suggestions, also called persistent search bar.

Alt text Alt text Alt text

Note

This project is not being actively maintained. Have a look here for information that might help you make changes to your own copy of the code base.

...

Usage

  1. In your dependencies, add
         compile 'com.github.arimorty:floatingsearchview:2.1.1'
    
  2. Add a FloatingSearchView to your view hierarchy, and make sure that it takes up the full width and height of the screen
  3. Listen to query changes and provide suggestion items that implement SearchSuggestion

Example:

       <com.arlib.floatingsearchview.FloatingSearchView
                android:id="@+id/floating_search_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:floatingSearch_searchBarMarginLeft="@dimen/search_view_inset"
                app:floatingSearch_searchBarMarginTop="@dimen/search_view_inset"
                app:floatingSearch_searchBarMarginRight="@dimen/search_view_inset"
                app:floatingSearch_searchHint="Search..."
                app:floatingSearch_suggestionsListAnimDuration="250"
                app:floatingSearch_showSearchKey="false"
                app:floatingSearch_leftActionMode="showHamburger"
                app:floatingSearch_menu="@menu/menu_main"
                app:floatingSearch_close_search_on_keyboard_dismiss="true"/>
  mSearchView.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
                  mSearchView.swapSuggestions(newSuggestions);
              }
          });

Left action mode:

The left action can be configured as follows:

Add

   app:floatingSearch_leftActionMode="[insert one of the options from table below]"
showHamburger
showSearch
showHome
noLeftAction

Listen to hamburger button clicks:

 mSearchView.setOnLeftMenuClickListener(
        new FloatingSearchView.OnLeftMenuClickListener() { ...} );          

To quickly connect your NavigationDrawer to the hamburger button:

   mSearchView.attachNavigationDrawerToMenuButton(mDrawerLayout);

Listen to home (back arrow) button clicks:

  mSearchView.setOnHomeActionClickListener(
         new FloatingSearchView.OnHomeActionClickListener() { ... });       

Configure menu items:

Alt text

Add a menu resource

    app:floatingSearch_menu="@menu/menu_main"

In the menu resource, set items' app:showAsAction="[insert one of the options described in the table below]"

never Puts the menu item in the overflow options popup
ifRoom Shows an action icon for the menu if the following conditions are met: 1. The search is not focused. 2. There is enough room for it.
always Shows an action icon for the menu if there is room, regardless of whether the search is focused or not.

Listen for item selections

   mSearchView.setOnMenuItemClickListener(new FloatingSearchView.OnMenuItemClickListener() {
      @Override
      public void onMenuItemSelected(MenuItem item) {                  
            
      }
   });

Configure suggestion item:

First, implement SearchSuggestion

Optional:

Set a callback for when a given suggestion is bound to the suggestion list.

For the history icons to show, you would need to implement this. Refer to the sample app for an example implementation.

   mSearchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() {
            @Override
            public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView, 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. 
            }

        });

Styling:

Available styling:

   <style name="SearchView">
           <item name="floatingSearch_backgroundColor"></item>
           <item name="floatingSearch_viewSearchInputTextColor"></item>
           <item name="floatingSearch_viewSuggestionItemTextColor"></item>
           <item name="floatingSearch_hintTextColor"></item>
           <item name="floatingSearch_dividerColor"></item>
           <item name="floatingSearch_clearBtnColor"></item>
           <item name="floatingSearch_leftActionColor"></item>
           <item name="floatingSearch_menuItemIconColor"></item>
           <item name="floatingSearch_suggestionRightIconColor"></item>
           <item name="floatingSearch_actionMenuOverflowColor"></item>
   </style>

RxBinding Extension

The RxBinding library allows you to listen for query changes using RxJava Obervables.

Observable<CharSequence> queryObservable = RxFloatingSearchView.queryChanges(view);
queryObservable.doOnNext { query -> Toast.makeText(this, "Query is %s".format(query), Toast.LENGTH_LONG).show() }.subscribe();

The Kotlin Extension

The Kotlin extension adds an extension function to the view for more goodness.

view.queryChanges(5).doOnNext { query -> Toast.makeText(this, "Query is %s".format(query), Toast.LENGTH_LONG).show() }.subscribe()

License

Copyright (C) 2015 Ari C.

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.