简体   繁体   English

Android搜索视图忽略searchHintIcon-searchHintIcon模糊

[英]Android Search View Ignoring searchHintIcon - searchHintIcon Blurry

I'm trying to hide the searchHintIcon using some code I found here on SO. 我正在尝试使用在SO上找到的一些代码隐藏searchHintIcon。

My Search View Theme: 我的搜索视图主题:

<style name="SearchViewTheme" parent="Base.Widget.AppCompat.SearchView">
    <item name="android:textColorHint">@android:color/white</item>
    <item name="android:searchHintIcon">@null</item>
</style>

My Search View XML Code: 我的搜索视图XML代码:

<SearchView
  android:id="@+id/search_view"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_alignParentTop="true"
  android:layout_toEndOf="@+id/iVProfilePicture"
  android:searchIcon="@drawable/search_icon"
  android:theme="@style/SearchViewTheme">
</SearchView>

My main reason for hiding the Icon is that it shows up really blurry when the search view is Uncollapsed: 我隐藏图标的主要原因是,当搜索视图为未折叠时,它的显示会非常模糊:

搜索查看错误

For comparison here is the collapsed search view: 为了进行比较,下面是折叠后的搜索视图:

普通搜索

Any Ideas how I'm able to: 任何想法我如何能够:

a) hide the hint icon or b) unblur the hint icon a)隐藏提示图标或b)取消模糊提示图标

Thanks in advance! 提前致谢!

so , knowing that you are adding your searchView in the actionbar , you can proceed like that : 因此,知道您要在操作栏中添加searchView,就可以像这样继续:

1- First : Inside the xml folder in res , create a an xml file : searchable.xml and give it a label and a hint 1-首先:在res的xml文件夹中,创建一个xml文件:searchable.xml并为其提供标签和提示

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="Search"
android:hint="Search" >
</searchable>

2- secondly: Add your searchView in the main menu of you're application, in the menu folder create your menu xml file, for exemple main.xml and add you're searchView 2-第二:在应用程序的主菜单中添加searchView,在菜单文件夹中创建菜单xml文件,例如main.xml并添加为searchView

 <item
    android:id="@+id/search"
    android:title="Search"
    app:showAsAction="always"
    android:icon="@drawable/ic_action_search"
    app:actionViewClass="android.support.v7.widget.SearchView" />

3 Thirdly: in your activity , Override the methode onCreateOptionsMenu, and add the code for the searchView 3第三:在您的活动中,重写onCreateOptionsMenu方法,并为searchView添加代码

SearchManager manager = (SearchManager) 
getSystemService(Context.SEARCH_SERVICE);
SearchView search = (SearchView) menu.findItem(R.id.search).getActionView();
search.setSearchableInfo(manager.getSearchableInfo(getComponentName()));

and if you want to manage the search, you can also add : 如果要管理搜索,还可以添加:

search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            // when a user is typing text in the searchView
            return false;
        }
    });

4-Fourth : in you're Manifest File add the following codes: -- in the the activity where you are doing you're search, add this : 4-4:在清单文件中添加以下代码:-在要搜索的活动中,添加以下代码:

 <activity android:name=".YourActivity">
<intent-filter>
     <action android:name="android.intent.action.SEARCH" />
</intent-filter>

<meta-data
    android:name="android.app.default_searchable"
    android:value=".YourActivity" />
<meta-data
    android:name="android.app.searchable"
    android:resource="@xml/searchable" />
</activity>

You're searchView icon will be invisible or blur when you are doing you're search. 您正在搜索时,searchView图标将不可见或模糊。 Sorry I know maybe you haven't need all this, but maybe it will be beneficial for others too. 对不起,我知道您可能并不需要所有这些,但也许对其他人也有好处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM