I am using Toolbar search widget in my project. Everything works fine but expect the thing which I am completely stuck up with removing the underline below search field in m
Just add this line if you are using a v7 or androidx widget
app:queryBackground="@android:color/transparent"
First you should get the bottom line simply like this:
searchPlate = (View) findViewById(R.id.search_plate);
Then you should set background color to transparent like this:
searchPlate.setBackgroundColor(Color.TRANSPARENT);
This works perfectly for androidx.appcompat.widget.SearchView!
You can try using the below code, works like a charm for me.
View v = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
v.setBackgroundColor(ContextCompat.getColor(context,android.R.color.transparent));
For AndroidX I used this based on other answers here,
mSearchView.findViewById(androidx.appcompat.R.id.search_plate)
.setBackgroundColor(Color.TRANSPARENT);
The code for changing the background color of SearchView edit text is below
public static void setSearchViewEditTextBackgroundColor(Context context, SearchView searchView, int backgroundColor){
int searchPlateId = context.getResources().getIdentifier("android:id/search_plate", null, null);
ViewGroup viewGroup = (ViewGroup) searchView.findViewById(searchPlateId);
viewGroup.setBackgroundColor(ComponentUtils.getColor(context, backgroundColor));
}
If your action bar background color is white then call the above method as follow.
setSearchViewEditTextBackgroundColor(this, searchView, R.color.white);
Now the underline from SearchView edit text will disappear.
The below piece of code works for me.
val searchView = menu?.findItem(R.id.action_search)?.actionView as SearchView
searchView.findViewById<View>(androidx.appcompat.R.id.search_plate).background = null