Remove the SearchIcon as hint in the searchView

后端 未结 13 2180
攒了一身酷
攒了一身酷 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:12

    Use "searchHintIcon" attribute in your styles for that:

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="searchViewStyle">@style/AppTheme.SearchView</item>
    </style>
    
    <style name="AppTheme.SearchView" parent="Widget.AppCompat.SearchView">
        <item name="searchHintIcon">@null</item>
    </style>
    

    You can replace @null with any drawable res you want

    0 讨论(0)
  • 2020-12-03 10:15

    It's answer

    ImageView searchViewIcon = (ImageView)searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
    
    ViewGroup linearLayoutSearchView =(ViewGroup) searchViewIcon.getParent();
    linearLayoutSearchView.removeView(searchViewIcon);
    
    0 讨论(0)
  • 2020-12-03 10:18

    Try these three lines:

    android:iconifiedByDefault="false"
    android:searchIcon="@null"
    android:searchHintIcon="@null"
    

    *It works only for android.widget.SearchView

    0 讨论(0)
  • 2020-12-03 10:18

    androidx.appcompat.widget.SearchView

    If you use androidx.appcompat.widget.SearchView:

    You can hide the icon using this:

    val magImage = searchView.findViewById<View>(androidx.appcompat.R.id.search_mag_icon) as ImageView
    magImage.layoutParams = LinearLayout.LayoutParams(0, 0)
    
    0 讨论(0)
  • 2020-12-03 10:20

    I've simply put @null to searchHintIcon attribute:

    <style name="SearchViewMy" parent="Widget.AppCompat.Light.SearchView">
        <item name="searchHintIcon">@null</item>
    </style>
    

    and applied that style in my app theme

    <style name="Theme.App" parent="Theme.AppCompat.Light.NoActionBar.FullScreen">
        <item name="searchViewStyle">@style/SearchViewMy</item>
    </style>
    

    Works for me.

    0 讨论(0)
  • 2020-12-03 10:23

    Simple solution is searchHintIcon attribute

    <style name="SearchViewStyleMyApp" parent="Widget.AppCompat.SearchView">
            <!-- Background for the search query section (e.g. EditText) -->
            <item name="queryBackground">@android:color/white</item>
            <!-- note that this is how you style your hint icon -->
            <item name="searchHintIcon">@null</item>
            <!-- The hint text that appears when the user has not typed anything -->
            <item name="queryHint">@string/search_hint</item>
        </style>
    
    0 讨论(0)
提交回复
热议问题