Chandru Chandru - 1 year ago 855
Android Question

How to remove white underline in a SearchView widget in Toolbar Android

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 my toolbar. I have tried many solutions and nothing works out. Below are the some of the solutions what i tried.

Requirement is to remove white underline in the image

enter image description here

Ist Solution:

//Removing underline

int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
View searchPlate = searchView.findViewById(searchPlateId);
if (searchPlate!=null) {
searchPlate.setBackgroundColor (Color.TRANSPARENT);
int searchTextId = searchPlate.getContext ().getResources ().getIdentifier ("android:id/search_src_text", null, null);


IInd Solution:

EditText searchEdit = ((EditText)searchView.findViewById(;

The above code works to change the background of EditText but still underline is displaying below close icon in SearchBar.

Complete code that I am using for SearchBar widget as follows:

public void onCreateOptionsMenu(Menu menu, MenuInflater infl) {
super.onCreateOptionsMenu(menu, infl);
MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(, menu);
final SearchView searchView = (SearchView) MenuItemCompat

SearchManager searchManager = (SearchManager) getActivity ().getSystemService (getActivity ().SEARCH_SERVICE);
searchView.setSearchableInfo (searchManager.getSearchableInfo (getActivity ().getComponentName ()));

//changing edittext color
EditText searchEdit = ((EditText)searchView.findViewById(;


<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android=""
<item android:id="@+id/search"
compat:actionViewClass="" />

possible duplicate of this

Thanks in advance, any kind of solutions and suggestions would be much useful for me.

Answer Source

Once try as follows

View v = searchView.findViewById(;
v.setBackgroundColor(Color.parseColor("here give actionbar color code"));

Hope this will helps you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download