miguelcatalan / materialsearchview Goto Github PK
View Code? Open in Web Editor NEWCute library to implement SearchView in a Material Design Approach
Home Page: http://miguelcatalan.info/2015/09/23/MaterialSearchView/
License: Apache License 2.0
Cute library to implement SearchView in a Material Design Approach
Home Page: http://miguelcatalan.info/2015/09/23/MaterialSearchView/
License: Apache License 2.0
Device: SGS3
Background for search view:
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp">
<shape>
<solid android:color="@android:color/white"/>
<corners android:radius="2dp"/>
</shape>
</item>
</layer-list>
White line at the bottom of search view.
It is because of View in search_view.xm at60 line.
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_alignParentBottom="true"
android:background="#fff"
android:backgroundTint="#10000000" />
i try to use MaterialSearchView in my application but i have this problem ?
the problem is the search icon and back icon is overlap each other.
and this is my menu :
<?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/searchview" android:title="جستجو" app:ico_icon="gmd-search"></item>
</menu>
Some info about release
By far, this is the best repository of Material search view. There might be some enhancement on closing the search bar. It will be more natural if some animation is added.
when i add this code searchView.setSuggestions(getResources().getStringArray(R.array.query_suggestions));
search view fill other views of app on runtime but by tapping on search button and press back other views showing
i am using your library but i use fragments.
So i do not inflate main menu in activity but inside fragment.
How to obtain reference to searchview ?
i tried
searchView = (MaterialSearchView)findViewById(R.id.search_view); but it returns null
Hi!
good library, thanks for it!
but i got some problem with devices with lollipop and above.
when i am clicking on search icon the keyboard is open, search is working. but...
ordinary title is showing and edit text doesn't show...
try this problem on few devices with lollipop
Is there any plans of integrating this with SearchRecentSuggestionsProvider? I guess setSuggestions should be overloaded to support a Cursor as well.
Hi,
I would like to have more information about your provider. I'm trying to implement a custom provider in order to manage an history.
For now I'm just using your SearchAdapter to be able to add suggestions but if I restart the application I lost them. I would like to manage my own provider in order to save my queries but I was not able to add a provider and an xml with searchable config.
I don't understand why the application told me that you already have a provider.
Can you give me more information ?
Suppose you start searching, and this causes the list of items to be filtered.
Now the user does multi-selection on the filtered items, which shows the actionMode on top of the action bar.
Sadly, in this case the keyboard is still shown, and it does work, yet the MaterialSearchView is behind so you can't see the query.
My request is to be able to let the query stay, temporarily disable entering text.
For now, a workaround is to find the EditText within the MaterialSearchView, and call setEnabled(false) on it.
Meaning:
final MaterialSearchView searchView = ...
final EditText searchEditText = (EditText) searchView.findViewById(com.miguelcatalan.materialsearchview.R.id.searchTextView);
searchEditText.setEnabled(...);
Another workaround is to hide the keyboard, but this is not a full solution because you can still theoretically focus on the view and show the keyboard again
how to dispatch event when tap on suggestion item ?
why not expose a method like showKeyboard?
I need it for use after VoiceSearch?
Ex:
....
if (matches != null && matches.size() > 0) {
String searchWrd = matches.get(0);
if (!TextUtils.isEmpty(searchWrd)) {
searchView.setQuery(searchWrd, false);
searchView.showKeyboard();
}
}
...
Great Library!
It seems that is not possible to use a toolbar with shadow.
I add extention fuction to your searchview. But in kotlin
Reactive:
public fun MaterialSearchView.asObserver(): Observable{
return Observable.create { subscriber ->
var watcher= object: MaterialSearchView.OnQueryTextListener{
override fun onQueryTextSubmit(query: String?): Boolean {
if (!subscriber.isUnsubscribed) {
subscriber.onNext(query)
return true
}
return false
}
override fun onQueryTextChange(newText: String?): Boolean {
if (!subscriber.isUnsubscribed) {
subscriber.onNext(newText)
return true
}
return false
}
}
this.setOnQueryTextListener(watcher)
}
}
Thanks the good library.
It will make activity or fragment invisible,after use setSuggestions method.
I have seen the pictures shown in the README.md ,and the activity is visible when show suggestions.
I need your help ,thanks.
I have the use case, that when filling the suggestion list using values that come from OnQueryTextListener
when user click on a suggestion i want to trigger a full search, like Google Play and other apps using
searchView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
searchView.setQuery(suggestion, true);
}
});
but with this trigger an OnQueryTextListener.onQueryTextChange()
before OnQueryTextListener.onQueryTextSubmit()
and that trigger is unnecessary in mostly cases
Digging in the code i see the function onSubmitQuery();
just allowing a String as parameter and provide a public method submitQuery(String query)
that call onSubmitQuery
internally that not trigger OnQueryTextListener.onQueryTextChange()
solve the problem.
I could do it, but first i want to know your opinion.
It would be great if you include support for Circular Reveal Animation on lollipop and above.
I have a scenario where I need to search view to be consistent on the activity I'm using it. After searching I noticed it disappears . I try to call showSearch for it to come back but that doesnt work. Any help?
it has NPE:
java.lang.NullPointerException at com.miguelcatalan.materialsearchview.MaterialSearchView.isVoiceAvailable(MaterialSearchView.java:270) at com.miguelcatalan.materialsearchview.MaterialSearchView.showVoice(MaterialSearchView.java:444) at
maybe "msv__" .
The reason is to avoid accidental overriding and name collisions of resources by the project and other libraries.
Show loader when submit a query.
When adapter get data from internet it takes some time, loader will be nice feature ;-)
I'm use theme
<style name="ShortStoryTheme" parent="AppBaseTheme">
<item name="android:textColorPrimary">@android:color/white</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:windowTranslucentStatus" tools:targetApi="19">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="windowActionBar">false</item>
<!-- Toolbar Theme / Apply white arrow -->
<item name="colorControlNormal">@android:color/white</item>
<item name="actionBarTheme">@style/ShortStory_AppTheme.ActionBarTheme</item>
<item name="android:windowActionBarOverlay" tools:targetApi="21">true</item>
<item name="android:background">@android:color/transparent</item>
<item name="windowNoTitle">true</item>
<item name="android:windowBackground">@color/theme_background</item>
<item name="actionMenuTextColor">@color/theme_icons</item>
<item name="android:textColorSecondary">@color/theme_icons</item>
<!-- Material Theme -->
<item name="colorPrimary">@color/nliveo_red_colorPrimary</item>
<item name="colorPrimaryDark">@color/nliveo_red_colorPrimaryDark</item>
<item name="colorAccent">@color/nliveo_green_colorAccent</item>
<item name="android:statusBarColor" tools:targetApi="21">@color/statusBarColor</item>
<item name="android:navigationBarColor" tools:targetApi="21">@color/navigationBarColor
</item>
<item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="21">true</item>
</style>
And occur error when preview.
java.lang.NullPointerException
at com.miguelcatalan.materialsearchview.MaterialSearchView.setBackground(MaterialSearchView.java:297)
at android.view.View.<init>(View.java:4328)
at android.view.ViewGroup.<init>(ViewGroup.java:573)
at android.widget.FrameLayout.<init>(FrameLayout.java:97)
at android.widget.FrameLayout.<init>(FrameLayout.java:92)
at android.widget.FrameLayout.<init>(FrameLayout.java:88)
at com.miguelcatalan.materialsearchview.MaterialSearchView.<init>(MaterialSearchView.java:87)
at com.miguelcatalan.materialsearchview.MaterialSearchView.<init>(MaterialSearchView.java:83)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:458)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:170)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:103)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:190)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:218)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:145)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:835)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:811)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:838)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:811)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:223)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:426)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:510)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:498)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:888)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:498)
at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:72)
at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:610)
at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:607)
at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:366)
at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:607)
at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:629)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:652)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:80)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:594)
at com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:152)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:452)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:402)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:137)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:589)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
at com.intellij.util.Alarm$Request$1.run(Alarm.java:351)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
I use a 20sp textSize for my toolbar title.
It looks weird when the searchView opens and the hint's textSize is only 16sp.
Thanks!
If the user types letters in search field it would be really nice that these letters are bold in the suggestion list.
That would be nice ux.
I don't understand where in the code it does it.
I can't find meaningful differences between the StickyActivity and the others.
If searchView's setOnItemClickListener is called before setSuggestions(String[] suggestions) is called former listener won't get triggered because setSuggestions(String[] suggestions) has overridden setOnItemClickListener itself.
public void setSuggestions(String[] suggestions) {
if (suggestions != null && suggestions.length > 0) {
mTintView.setVisibility(VISIBLE);
final SearchAdapter adapter = new SearchAdapter(mContext, suggestions, suggestionIcon);
setAdapter(adapter);
setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
setQuery((String) adapter.getItem(position), false);
}
});
} else {
mTintView.setVisibility(GONE);
}
}
Please check mSuggestionsListView has no onItemClickListener attached before setting new one in the setSuggestions(String[] suggestions) method.
we have many attributes, but this one can only be set via code.
I guess this issue is quite similar to #14 but in case I'm setting a coloured background to the SearchView
yet seeing a line below it. I tried setting elevation="0dp"
which didn't seem to work
Check the screenshot below.
It was wondering to change animation speed values, as going through the source code. Animation fields are constants and cannot be override, It would be best if you include tag or methods for passing custom values for animation.
setVoiceSearch dosn't declar in this source code . please check this .
my code is :
searchView = (MaterialSearchView) findViewById(R.id.search_view);
searchView.showVoice(false);
searchView.setVoiceSearch(true); //or false // Error
searchView.setOnQuery.....
I want get data from server, help me!
My company has a build server without Internet access. Any 3rd-party library needs to be uploaded separately. I've searched Maven but I couldn't find it. Where and how can I download the jar/aar file of your library?
java.lang.NullPointerException
at com.miguelcatalan.materialsearchview.MaterialSearchView.isVoiceAvailable(MaterialSearchView.java:268)
at com.miguelcatalan.materialsearchview.MaterialSearchView.showVoice(MaterialSearchView.java:444)
at com.miguelcatalan.materialsearchview.MaterialSearchView.initiateView(MaterialSearchView.java:159)
at com.miguelcatalan.materialsearchview.MaterialSearchView.<init>(MaterialSearchView.java:90)
at com.miguelcatalan.materialsearchview.MaterialSearchView.<init>(MaterialSearchView.java:82)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:466)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:173)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:106)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:168)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:214)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:142)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:413)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:321)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:510)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:498)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:959)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:498)
at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:72)
at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:610)
at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:607)
at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:361)
at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:607)
at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:629)
at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel$7.run(AndroidDesignerEditorPanel.java:519)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:337)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:327)
at com.intellij.util.ui.update.MergingUpdateQueue$3.run(MergingUpdateQueue.java:271)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:286)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:244)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:234)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
at com.intellij.util.Alarm$Request$1.run(Alarm.java:352)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
what is wrong?
is see this on the layout file
Hi,
how i Can click an element of suggestion array?? In the original searview ther is the method setOnSuggestionListener
THX
I'm using the MaterialSearchView with TabLayout, AppBarLayout and RecyclerView. The toolbar is hidden when the list is scrolling. I tried the following layouts:
A. The search view is below tabs:
AppBarLayout
ToolBar
TabLayout
MaterialSearchView
/AppBarLayout
B. The toolbar scrolling doesn't work anymore:
AppBarLayout
FrameLayout
ToolBar
MaterialSearchView
/FrameLayout
TabLayout
/AppBarLayout
What I expect is the effect like the "My apps" section in the Play Store app. The search view is actually placed above the activity though. Any suggestions?
It would be nice to have the option to allow empty query string (Ex: app:empty_allowed='true')
Because we can add various intent values for it:
http://developer.android.com/reference/android/speech/RecognizerIntent.html
modify the sample to have more action items on the right of the search menu item, and then click the search menu item.
The reveal animation still starts from the most right area, instead of from the search menu item.
Here's an example of the modification that's needed to do it:
menu_main.xml
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_action_action_search"
android:title="@string/abc_search_hint"
app:showAsAction="always"/>
<item
android:icon="@android:drawable/ic_menu_edit"
android:title="edit"
app:showAsAction="always"/>
</menu>
Please fix this.
Do think you about searching not only from beginning and displaying the suggestions?
I have nothing seen in the readme about it. Only in your sample app.
Voice voice is invalid, the right ICONS don't show this is why, I have realized the following code
searchView.setVoiceSearch(true);
Have you an exemple of your SearchView in a Fragment ? I need to use a fragment with your SearchView.
Hello!
First of all thanks for sharing this library, I was looking for something similar to use in my projects! :)
Currently I made a fork of it and I´m adding some personal changes that might be useful for you also, so I could make a PR if you´re interested:
I hope you like the changes, I will create the PR soon so you can review/merge if you like them.
Cheers!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.