0

this is what I have in xml file

    <SearchView
        android:id="@+id/searchView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:iconifiedByDefault="false">
    </SearchView>

This is how its looks on device

enter image description here

But I want this think to look like this:

enter image description here

How to do that ? Is that possible with searchView or I should use EditText with image inside ?

P.S: Searchview is not in action bar

Jim
  • 8,874
  • 16
  • 68
  • 125

2 Answers2

2

I think you have to change the background of your android:id="@+id/search_plate"

Changing the background drawable of the searchview widget

Community
  • 1
  • 1
GioLaq
  • 2,489
  • 21
  • 26
0

This behaviour is changed by the setIconifiedByDefault method (http://developer.android.com/reference/android/widget/SearchView.html#setIconifiedByDefault(boolean)). If you call the method when setting up the SearchView, like below, the icon will be outside the TextView:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.mymenu, menu);

    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    // ...
    searchView.setIconifiedByDefault(false); // the icon will be outside the search view
}

So, to get the desired behaviour, just don't call setIconifiedByDefault (which is, according to the docs, the same as calling it with a true parameter)

Bolhoso
  • 895
  • 1
  • 7
  • 14