-4

I want to create a search bar in toolbar like this.Search icon show with EditText box

Search icon show with EditText box

Anand Jain
  • 2,365
  • 7
  • 40
  • 66
  • Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the [How to Ask](http://stackoverflow.com/help/how-to-ask) page for help clarifying this question. – Roman Marusyk Sep 22 '15 at 08:12
  • search icon show with edit text and below of other icon – Anand Jain Sep 22 '15 at 08:14
  • Its called a SearchView. You can google for it – Tim Sep 22 '15 at 08:17

2 Answers2

0

There is a property in the xml of EditText

android:drawableLeft="@drawable/yoursearchIcon"

You may use this in your xml of EditText with the icon you want for search. To use default search icon, access it with android.drawable....

Roadblock
  • 2,041
  • 2
  • 24
  • 38
0

Declare a menu item:-

<item android:id="@+id/action_search"
android:title="Search"
android:icon="@drawable/abc_ic_search_api_mtrl_alpha"
app:showAsAction="ifRoom|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView" />

In onCreateOptionsMenu Method:-

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    return true;
}
Anand Jain
  • 2,365
  • 7
  • 40
  • 66