Search View Layout

Additional

Language
Java
Version
N/A
Created
Oct 28, 2015
Updated
Sep 24, 2018
Owner
Sahil Dave (sahildave)
Contributors
Tobias Preuss (johnjohndoe)
Sahil Dave (sahildave)
vguzzi
tim-bm
ajans
tfmend
ysy950803
balazsgerlei
8
Activity
Badge
Generate
Download
Source code
APK file

Advertisement

THIS PROJECT IS DEPRECATED

Component is not maintained anymore.

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"/>


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.transparentColorDrawable collapsed =newColorDrawable( ContextCompat.getColor(this, R.color.colorPrimary)); // Create Drawable for expanded state. Default color is #F0F0F0ColorDrawable expanded =newColorDrawable( ContextCompat.getColor(this, R.color.default_color_expanded)); // Send both colors to searchViewLayout searchViewLayout.setTransitionDrawables(collapsed, expanded);

Listen to search complete by:searchViewLayout.setSearchListener(newSearchViewLayout.SearchListener() { @OverridepublicvoidonFinished(StringsearchKeyword) { 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(newSearchViewLayout.OnToggleAnimationListener() { @OverridepublicvoidonStart(booleanexpanded) { if(expanded) { fab.hide(); } else { fab.show(); } } @OverridepublicvoidonFinish(booleanexpanded) { } });

Listen to search box complete by:searchViewLayout.setSearchBoxListener(newSearchViewLayout.SearchBoxListener() { @OverridepublicvoidbeforeTextChanged(CharSequences, intstart, intcount, intafter) { } @OverridepublicvoidonTextChanged(CharSequences, intstart, intbefore, intcount) { } @OverridepublicvoidafterTextChanged(Editables) { } });

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