Search View Layout


Source link: https://github.com/sahildave/Search-View-Layout

Implementation of Lollipop+ Dialer and Google Maps.

DEMO

Add in View

Add to your layout by using the include tag.

<include layout="@layout/widget_search_bar"/>

API

This overlays the full activity and shows the fragment which you have assigned by using setExpandedContentFragment.

searchViewLayout.setExpandedContentFragment(this, new SearchStaticFragment());

If you want to animate your Toolbar too like the demo gif, you can enable it by using handleToolbarAnimation.

searchViewLayout.handleToolbarAnimation(toolbar);

Setting Background colors for Transition. Default should also work just fine:

// Create Drawable for collapsed state. Default color is android.R.color.transparent ColorDrawable collapsed = new ColorDrawable(
  ContextCompat.getColor(this, R.color.colorPrimary));
  // Create Drawable for expanded state. Default color is #F0F0F0 ColorDrawable expanded = new ColorDrawable(
  ContextCompat.getColor(this, R.color.default_color_expanded));
  // Send both colors to searchViewLayout searchViewLayout.setTransitionDrawables(collapsed, expanded);

Listen to search complete by:

searchViewLayout.setSearchListener(new SearchViewLayout.SearchListener() {

  @Override
  public void onFinished(String searchKeyword) {

searchViewLayout.collapse();

Snackbar.make(searchViewLayout, "Search Done - " + searchKeyword, Snackbar.LENGTH_LONG).show();

  
}
 
}
);

Listen to collapse/expand animation by using setOnToggleAnimationListener. For eg the FAB in demo hides on expanded and shows on collapse.

searchViewLayout.setOnToggleAnimationListener(new SearchViewLayout.OnToggleAnimationListener() {

  @Override
  public void onStart(boolean expanded) {

if(expanded) {

 fab.hide();

}
 else {

 fab.show();

}

  
}

@Override
  public void onFinish(boolean expanded) {
 
}
 
}
);

Listen to search box complete by:

searchViewLayout.setSearchBoxListener(new SearchViewLayout.SearchBoxListener() {

  @Override
  public void beforeTextChanged(CharSequence s, int start, int count, int after) {

  
}

  @Override
  public void onTextChanged(CharSequence s, int start, int before, int count) {

  
}

  @Override
  public void afterTextChanged(Editable s) {

  
}
 
}
);

Setting Hints

If you want to set hints in the view, there are three APIs. setCollapsedHint would come up in the default/collapsed state. setExpandedHint would work for expanded state i.e. after click the view and the keyboard is up. setHint would set both the hints in one go, use this you want to show the same hint in both the states.

searchViewLayout.setCollapsedHint("Collapsed Hint");
 searchViewLayout.setExpandedHint("Expanded Hint");
 searchViewLayout.setHint("Global Hint");

Setting Icons Use setCollapsedIcon, setExpandedBackIcon, setExpandedSearchIcon to setup icons according to your choice. The argument should be a DrawableRes

NOTES

  1. If you want to add a scrolling widget in your setExpandedContentFragment, add a onTouchListener and disallow the parent intercept by using v.getParent().requestDisallowInterceptTouchEvent(true); Check out fragments in sample for the implement of ListView, RecyclerView and ScrollView.

    recyclerView.setOnTouchListener(new View.OnTouchListener() {
    
      // Setting on Touch Listener for handling the touch inside ScrollView
      @Override
      public boolean onTouch(View v, MotionEvent event) {
    
    // Disallow the touch request for parent scroll on touch of child view
    
    v.getParent().requestDisallowInterceptTouchEvent(true);
    
    return false;
      
    }
     
    }
    );
     
  2. The default height of the view is 120dp which is also present in the dimens.xml file as

    <dimen name="search_view_layout_approx_height">120dp</dimen>

    You can use it for adding margin on top of your main content layout.

GET

Available at jCenter and mavenCentral.

dependencies {

  compile 'xyz.sahildave:searchviewlayout:0.6' 
}

CHANGELOG

0.6

  • Added support for API 15

0.5

  • Added support for fragment-v4

0.4

  • Moved anim files to /animator res dir

0.3

  • Added search edit text API
  • Larger touch target

0.2

  • Added APIs for setting icons
  • Improved animations by using onAnimationUpdate

0.1

  • Added hints API.
  • Added search_view_layout_approx_height

0.0.2

  • Added API setTransitionDrawables which solves crashes in < API 19

Contribute

Contribute by creating issues (tagged enhancement, bugs) in the repo or create a pull request.

Resources

A common RecyclerView.Adapter implementation which supports any kind of items and has useful data operating APIs such as remove, add, etc.

EasyForm makes a form creation and field validation easy.

SegmentedControlView is unswipable button style control view. Inspired by iOS's UISegmentedControl, buttons are evenly spaced in width. Simple usage! Just specify the highlight colors and unselected text colors are calculated automatically.

Cool ImageVeiw effects.

A layout that you can swipe/slide to show another layout.

A library that uses google's mobile vision api and simplify the QR code reading process.

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