FloatingSearchView


Source link: https://github.com/renaudcerrato/FloatingSearchView

FloatingSearchView

Yet another floating search view implementation, also known as persistent search: that implementation fully supports menu (including submenu), logo and animated icon. Dropdown suggestions are backed by a RecyclerView and you can provide your own RecyclerView.Adapter, ItemDecorator or ItemAnimator. No hiding.

DEMO APK

Usage

Add a FloatingSearchView to your view hierarchy, make sure that it takes up the full width and height:

<com.mypopsy.widget.FloatingSearchView

android:id="@+id/search"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingTop="16dp"

android:paddingRight="8dp"

android:paddingLeft="8dp"

android:background="#90000000"

android:hint="@string/hint"

app:logo="@drawable/logo"

app:fsv_menu="@menu/search"/>

See the supported attributes.

Then, configure your instance and set your listeners to react accordingly:

mSuggestionsAdapter = new MySuggestionsAdapter();
 // use a RecyclerView.Adapter mSearchView.setAdapter(mSuggestionsAdapter);
 ... mSearchView.setOnIconClickListener(...);
 mSearchView.setOnSearchListener(...);

mSearchView.addTextChangedListener(...);
 mSearchView.setOnSearchFocusChangedListener(...);

Look at the sample.

Menu

The implementation fully supports menu (and submenu):

<com.mypopsy.widget.FloatingSearchView  ...  app:fsv_menu="@menu/search" />
mSearchView.setOnMenuItemClickListener(...);

Menu items can be automatically hidden when the search view gets focus depending on the value of the MenuItem's showAsAction:

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
  <item android:id="@+id/menu1" ... app:showAsAction="always"/> // always shown
  <item android:id="@+id/menu2" ... app:showAsAction="ifRoom"/> // will hide on focus

<item android:id="@+id/menu3" ... app:showAsAction="never"/>  // will go into the overflow menu </menu>

Animated Icon

FloatingSearchView will automagically animate icons drawable, given they declare a progress property:

  • void setProgress(float)
  • float getProgress()

example: DrawerArrowDrawable or ToggleDrawable

Other

Since the implementation tries to focus on core logic instead of business logic as much as possible, common features like "tap to clear", "speech to text" or "loading progress" are voluntarily NOT built-in because they can be easily implemented using menu items as seen in the sample.

Styling

FloatingSearchView do not expose most of TextView's XML attributes ( textColor, textSize...). You can style them using theme attributes by applying app:theme for example:

First, create a dedicated theme, possibly heriting from your application theme:

<!-- your custom theme --> <style name="CustomFloatingSearchViewTheme" parent="AppTheme">
  <item name="editTextStyle">@style/searchViewEditTextStyle</item>
  <item name="android:divider">#c9c9c9</item>
  <item name="android:dividerHeight">1dp</item>
  <item name="colorControlNormal">#696969</item> </style>  <!-- your custom search view text style -->  <style name="searchViewEditTextStyle" parent="Widget.AppCompat.EditText">
  <item name="android:textSize">18sp</item>
  <item name="android:textColor">?android:attr/textColorPrimary</item>
  <item name="android:imeOptions">actionSearch</item> </style>

Then, apply your custom theme through app:theme:

<com.mypopsy.widget.FloatingSearchView  ...  app:theme="@style/CustomFloatingSearchViewTheme" />

Look at the sample.

Install

This repository can be found on JitPack:

https://jitpack.io/#renaudcerrato/FloatingSearchView

Add it in your root build.gradle at the end of repositories:

allprojects {

repositories {

 ...
 maven {
 url "https://jitpack.io" 
}

}
  
}
 

Add the dependency:

dependencies {

 compile 'com.github.renaudcerrato:FloatingSearchView:1.0.1'  
}
 

Resources

This library will help developers to avoid writing repetitive code as mostly developers do while writing Adapter for RecyclerView. This library also provide convenient way to get position of a view which is clicked by user. This tiny library can save developers time and help them writing clean code inside Adapters.

A sweet message box designed for Android developers.

Android Simple Network Library for HTTP and Image Requests with cool features implemented with Simple Demo using some Material Design UI Elements.

Simple Universal Adapter and ViewHolders generator for Recycler View.

A progress view. It is similar to the Fitbit application's progress bar.

Create a simple button to play a media source.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes