I have simple SearchView androidx.appcompat.widget.SearchView
not android.support.v7.widget.SearchView
.
I want to remove SearchView icon when its on focus QueryTextFocusChangeListener
.
After I google it, I found two solutions which is for android.support.v7.widget.SearchView
.
This one I cannot find R.id.search_mag_icon
, so it didn't work.
SearchView searchView = (SearchView)searchViewItem.getActionView(); searchView.findViewById(R.id.search_mag_icon).setVisibility(View.GONE);
Setting app:searchIcon="@null"
makes icon gone, but its gone at the beginning. I want to remove icon only when its on focus. I tried set searchIcon="@null"
programmatically but I cannot find it.
app:searchIcon="@null"
Again, I'm using androidx.appcompat.widget.SearchView
. Please help me. I spent long time but still
suffering.
I don't think it can be done programmatically. Check out mSearchHintIcon
in SearchView.java
(android source). It is private.
Try 'app:searchHintIcon':
<androidx.appcompat.widget.SearchView
android:id="@+id/main_sv"
app:searchHintIcon="@drawable/blank_placeholder_drawable"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Or you can also change android:tint="#fafafa"
to any placeholder drawable to match the background color.
In case you are using AppCompat use
app:iconifiedByDefault="false"
app:searchIcon="@null"
Else use android in place of app in above code as
android:iconifiedByDefault="false"
android:searchIcon="@null"
Try this with your SearchView
:
searchView.setIconifiedByDefault(false);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.