从搜索查看插件删除默认搜索图标 [英] Removing default search icon from SearchView widget

查看:205
本文介绍了从搜索查看插件删除默认搜索图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能删除它出现在搜索查看小部件(不动作条)暗示默认搜索图标?通过样式我可以改变图标,但我不能找到一种方法来去除呢?

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:


  1. http://www.tutorialspoint.com/android/android_auto_complete.htm

  1. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆