I want to add underline to searchview widget like the blue underline in the given image below.But my searchview doesn't display any underline.Even when i type text no underline is displayed.Below is the code i am using.
menu_home.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.peoplecloud.app.guggu.activities.HomeActivity">
<item
android:id="@+id/menu_item_search"
android:icon="@drawable/icon_search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always"
>
</item>
</menu>
Code-
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.clear();
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_home, menu);
searchItem = menu.findItem(R.id.menu_item_search);
searchItem.setVisible(false);
mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_item_search));
mSearchView.setQueryHint("Search GIFs");
setupSearchView(searchItem);
return super.onCreateOptionsMenu(menu);
}
private void setupSearchView(MenuItem searchItem) {
searchItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM
| MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
mSearchView.setQuery("test", true);
mSearchView.setOnQueryTextListener(this);
mSearchView.setFocusable(true);
mSearchView.requestFocusFromTouch();
mSearchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus)
{
if (hasFocus) {
showInputMethod(view.findFocus());
}
}
});
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s)
{
...
return true;
}
@Override
public boolean onQueryTextChange(String s) {
return false;
}
});
}
Try the following, here a custom search view layout is added.
menu_home.xml
search_layout.xml
onCreateOptionsMenu