To achieve desired look of SearchView, you can use styles.
First, you need to create style
for your SearchView, which should look something like this:
<style name="CustomSearchView" parent="Widget.AppCompat.SearchView">
<item name="searchIcon">@null</item>
<item name="queryBackground">@null</item>
</style>
Whole list of attributes you can find at this article, under the "SearchView" section.
Secondly, you need to create a style
for your Toolbar
, which is used as ActionBar:
<style name="ToolbarSearchView" parent="Base.ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="searchViewStyle">@style/CustomSearchView</item>
</style>
And finally you need to update your Toolbar theme attribute this way:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="@style/ToolbarSearchView" />
Result:
NOTE: You need to change your Toolbar
theme attribute directly. If you'll just update your main theme searchViewStyle
attribute it wouldn't affect your Toolbar
.