title: ActionBar Mic Button(Voice Search) in SearchView
body: <p>I am implementing <code>Action Bar</code>. I want 2 buttons in Search field area of <code>Action Bar SearchView</code> like Flipkart app. </p>
  
  <p><img src="https://i.stack.imgur.com/qNVKy.png" alt="Flipkart app have two buttons in SearchView"></p>
  
  <p>Like above screenshot, I want 2 buttons, first one is for Voice Search and another is for Barcode Scanner, when Search icon clicked and <code>SearchView</code> of <code>Actionbar</code> appears. I am able to implement <code>actionbar serahcview</code> with search icon. But I am bit confused why voice search not appearing in my app. Have a look on my source code.</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          MenuInflater inflater = getMenuInflater();
          inflater.inflate(R.menu.main, menu);
  
          SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
  
          setSearchTextColour(searchView);
          setCloseSearchIcon(searchView);
  
          return super.onCreateOptionsMenu(menu);
      }
  
      @Override
      public boolean onPrepareOptionsMenu(Menu menu) {
          return super.onPrepareOptionsMenu(menu);
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
  
          switch(item.getItemId()) {
          case R.id.action_search:
  
              return true;
          default:
              return super.onOptionsItemSelected(item);
          }
      }
  
      private void setSearchTextColour(SearchView searchView) {
          int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
          EditText searchPlate = (EditText) searchView.findViewById(searchPlateId);
          searchPlate.setTextColor(getResources().getColor(R.color.novoda_blue));
  //        searchPlate.setBackgroundResource(R.drawable.edit_text_holo_light);
          searchPlate.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
      } 
  
   private void setCloseSearchIcon(SearchView searchView) {
          try {
              Field searchField = SearchView.class.getDeclaredField("mCloseButton");
              searchField.setAccessible(true);
              ImageView closeBtn = (ImageView) searchField.get(searchView);
              closeBtn.setImageResource(R.drawable.action_cancel);
  
              searchField = SearchView.class.getDeclaredField("mVoiceButton");
              searchField.setAccessible(true);
              ImageView voiceBtn = (ImageView) searchField.get(searchView);
              voiceBtn.setImageResource(R.drawable.ic_launcher);
  
          } catch (NoSuchFieldException e) {
              Log.e("SearchView", e.getMessage(), e);
          } catch (IllegalAccessException e) {
              Log.e("SearchView", e.getMessage(), e);
          }
      }
  </code></pre>
  
  <p><strong>Screenshot of What I got from above code :</strong></p>
  
  <p><img src="https://i.stack.imgur.com/Db510.png" alt="Output of Above Code"></p>
  
  <p>Any help would be highly appreciated.</p>