从搜索查看插件删除默认搜索图标 [英] Removing default search icon from SearchView widget
问题描述
我怎样才能删除它出现在搜索查看小部件(不动作条)暗示默认搜索图标?通过样式我可以改变图标,但我不能找到一种方法来去除呢?
How can i remove default search icon which appears as a hint in SearchView widget(not in actionbar)?Through styles i can change the icon but i can't find a way to remove it?
推荐答案
您可以覆盖它:
int searchImgId = context.getResources().getIdentifier("android:id/search_mag_icon", null, null);
ImageView searchImage = (ImageView) searchView.findViewById(searchImgId);
searchImage.setVisibility(View.GONE);
如果您的搜索视图在布局,那么请使用带的EditText关闭按钮:
If your search view is in layout then please use EditText with close button:
<一个href=\"https://github.com/yanchenko/droidparts/blob/develop/droidparts/src/org/droidparts/widget/ClearableEditText.java\" rel=\"nofollow\">https://github.com/yanchenko/droidparts/blob/develop/droidparts/src/org/droidparts/widget/ClearableEditText.java
如果你想创建自己的,然后使用框架布局,并添加文字更改侦听到奶源关闭或取消按钮的可见性。
If you want to create your own then use frame layout and add text change listener to mange visibility of close or cancel button.
有关于UI搜索视图几个讨论:
there are few discussion regarding search view in UI:
<一个href=\"http://stackoverflow.com/questions/6355096/how-to-create-edittext-with-crossx-button-at-end-of-it\">How与交叉(X)按钮在它结束时创造的EditText?
如果你想显示搜索列表然后使用替代的EditText AutoCompleteTextView。
If you want to show search list then use AutoCompleteTextView instead of EditText.
您可以从以下链接阅读教程:
you can read tutorial from below link:
- http://www.tutorialspoint.com/android/android_auto_complete.htm
2 <一个href=\"http://examples.java$c$cgeeks.com/android/core/widget/autocompletetextview/android-auto-complete-example/\" rel=\"nofollow\">http://examples.java$c$cgeeks.com/android/core/widget/autocompletetextview/android-auto-complete-example/
3 <一个href=\"http://androidexample.com/Show_AutoComplete_Suggestions_-_Android_Example/index.php?view=article_discription&aid=105&aaid=127\" rel=\"nofollow\">http://androidexample.com/Show_AutoComplete_Suggestions_-_Android_Example/index.php?view=article_discription&aid=105&aaid=127
我希望它会工作。
这篇关于从搜索查看插件删除默认搜索图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!