Remove the SearchIcon as hint in the searchView

后端 未结 13 2183
攒了一身酷
攒了一身酷 2020-12-03 09:59

I am doing an application where for example when i click on the image(it is a searchView)

\"enter

相关标签:
13条回答
  • 2020-12-03 10:30

    TL;DR: Simply setting the EditText's hint to the empty string is enough to remove the hint icon.

    I found an answer that actually works. There's a lot of stuff on changing the icon using reflection - such as discussed at Styling the ActionBar SearchView. This website IS a great resource, but unfortunately the search hint ImageView does not change (even though the reflection does not cause errors). The only way that I was able to remove this image was this:

    try {
        int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
        EditText searchPlate = (EditText) searchView.findViewById(searchPlateId);
        searchPlate.setHint("");
    }
    catch (Throwable t)
    {
        t.printStackTrace();
    }
    

    You should place this in your onCreateOptionsMenu method, and get a reference to your XML-declared SearchView using something like:

    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    
    0 讨论(0)
提交回复
热议问题